postgres icon indicating copy to clipboard operation
postgres copied to clipboard

Missing autoIncrement in postgres table schema output

Open wmh opened this issue 3 years ago • 3 comments

This is my table schema

CREATE TABLE public.log_usage (
    log_id bigint NOT NULL
);

ALTER TABLE public.log_usage ALTER COLUMN log_id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME public.log_usage_log_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);

ALTER TABLE ONLY public.log_usage
    ADD CONSTRAINT pk_log_usage PRIMARY KEY (log_id);

And this is the generator output:

type LogUsage struct {
	LogID           int64     `gorm:"column:log_id;type:int8;primaryKey" json:"log_id"`
}

Expected:

type LogUsage struct {
	LogID           int64     `gorm:"column:log_id;type:int8;primaryKey;autoIncrement:true" json:"log_id"`
}

wmh avatar Mar 17 '22 04:03 wmh

Method AutoIncrement does not work for postgres driver, so GEN cannot generate tag autoIncrement:true

tr1v3r avatar Mar 19 '22 09:03 tr1v3r

type Employee struct {
	ID        string    `json:"id" gorm:"primaryKey;type:INTEGER;autoIncrement;"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
	DeletedAt time.Time `json:"deletedAt"`
	Name      string    `json:"name" gorm:"index;size:50"`
}

@riverchu any workaround for my case to enable auto increment as also my code don't work as expected

kateile avatar Mar 21 '22 13:03 kateile

i wonder about your use case.As far as i know, autoIncrement works when you calling autoMigrate?am i right?

tr1v3r avatar Mar 21 '22 16:03 tr1v3r