ariga / atlas

Manage your database schema as code
https://atlasgo.io
Apache License 2.0
5.9k stars 263 forks source link

when use schema_diff with error executing "schema_diff" at <sql $>: error calling sql: alter table "xxx": unexpected attribute change (expect IDENTITY): [] #1965

Open linyongzuo opened 1 year ago

linyongzuo commented 1 year ago

create table sql in A: /* Navicat Premium Data Transfer

Source Server : k8s-pre Source Server Type : PostgreSQL Source Server Version : 140006 Source Host : pgm-bp15jmckg1a5831y.pg.rds.aliyuncs.com:5432 Source Catalog : authentication-center Source Schema : public

Target Server Type : PostgreSQL Target Server Version : 140006 File Encoding : 65001

Date: 08/08/2023 15:15:17 */


-- Table structure for t_invited_user


DROP TABLE IF EXISTS "public"."t_invited_user"; CREATE TABLE "public"."t_invited_user" ( "f_id" int4 NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 START 1 ), "f_created_at" timestamptz(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, "f_updated_at" timestamptz(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, "f_deleted_at" timestamptz(6), "f_invite_user_id" int8 NOT NULL, "f_invite_enterprise_id" int8 NOT NULL, "f_invited_phone" varchar(255) COLLATE "pg_catalog"."default", "f_invited_email" varchar(255) COLLATE "pg_catalog"."default", "f_role_ids" varchar(255) COLLATE "pg_catalog"."default", "f_code" varchar(255) COLLATE "pg_catalog"."default" NOT NULL, "f_status" int2 NOT NULL, "f_expired_at" timestamptz(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, "f_invited_id" int8 NOT NULL, "f_organization_id" varchar(255) COLLATE "pg_catalog"."default" NOT NULL ) ; ALTER TABLE "public"."t_invited_user" OWNER TO "easygo"; COMMENT ON COLUMN "public"."t_invited_user"."f_created_at" IS '创建时间'; COMMENT ON COLUMN "public"."t_invited_user"."f_updated_at" IS '最后更新时间'; COMMENT ON COLUMN "public"."t_invited_user"."f_deleted_at" IS '删除时间'; COMMENT ON COLUMN "public"."t_invited_user"."f_invite_user_id" IS '邀请人id'; COMMENT ON COLUMN "public"."t_invited_user"."f_invite_enterprise_id" IS '邀请人企业'; COMMENT ON COLUMN "public"."t_invited_user"."f_invited_phone" IS '被邀请人手机号'; COMMENT ON COLUMN "public"."t_invited_user"."f_invited_email" IS '被邀请人邮箱'; COMMENT ON COLUMN "public"."t_invited_user"."f_role_ids" IS '角色id'; COMMENT ON COLUMN "public"."t_invited_user"."f_code" IS '验证码消息'; COMMENT ON COLUMN "public"."t_invited_user"."f_status" IS '验证码状态 1:可用,2:不可用'; COMMENT ON COLUMN "public"."t_invited_user"."f_expired_at" IS '失效时间'; COMMENT ON COLUMN "public"."t_invited_user"."f_invited_id" IS '业务主键'; COMMENT ON COLUMN "public"."t_invited_user"."f_organization_id" IS '组织机构'; COMMENT ON TABLE "public"."t_invited_user" IS '邀请用户信息';


-- Primary Key structure for table t_invited_user


ALTER TABLE "public"."t_invited_user" ADD CONSTRAINT "t_invite_user_pkey" PRIMARY KEY ("f_id");

create table sql in B: /* Navicat Premium Data Transfer

Source Server : 线上 Source Server Type : PostgreSQL Source Server Version : 140004 Source Host : pgm-bp1p0s543156b0xi194100.pg.rds.aliyuncs.com:5432 Source Catalog : authentication-center Source Schema : public

Target Server Type : PostgreSQL Target Server Version : 140004 File Encoding : 65001

Date: 08/08/2023 15:15:52 */


-- Table structure for t_invited_user


DROP TABLE IF EXISTS "public"."t_invited_user"; CREATE TABLE "public"."t_invited_user" ( "f_id" int4 NOT NULL DEFAULT nextval('t_invited_user_f_id_seq'::regclass), "f_created_at" timestamptz(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, "f_updated_at" timestamptz(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, "f_deleted_at" timestamptz(6), "f_invite_user_id" int8 NOT NULL, "f_invite_enterprise_id" int8 NOT NULL, "f_invited_phone" varchar(255) COLLATE "pg_catalog"."default", "f_invited_email" varchar(255) COLLATE "pg_catalog"."default", "f_role_ids" varchar(255) COLLATE "pg_catalog"."default", "f_code" varchar(255) COLLATE "pg_catalog"."default" NOT NULL, "f_status" int2 NOT NULL, "f_expired_at" timestamptz(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, "f_invited_id" int8 NOT NULL, "f_organization_id" varchar(255) COLLATE "pg_catalog"."default" NOT NULL ) ; ALTER TABLE "public"."t_invited_user" OWNER TO "easygopgtmp01"; COMMENT ON COLUMN "public"."t_invited_user"."f_created_at" IS '创建时间'; COMMENT ON COLUMN "public"."t_invited_user"."f_updated_at" IS '最后更新时间'; COMMENT ON COLUMN "public"."t_invited_user"."f_deleted_at" IS '删除时间'; COMMENT ON COLUMN "public"."t_invited_user"."f_invite_user_id" IS '邀请人id'; COMMENT ON COLUMN "public"."t_invited_user"."f_invite_enterprise_id" IS '邀请人企业'; COMMENT ON COLUMN "public"."t_invited_user"."f_invited_phone" IS '被邀请人手机号'; COMMENT ON COLUMN "public"."t_invited_user"."f_invited_email" IS '被邀请人邮箱'; COMMENT ON COLUMN "public"."t_invited_user"."f_role_ids" IS '角色id'; COMMENT ON COLUMN "public"."t_invited_user"."f_code" IS '验证码消息'; COMMENT ON COLUMN "public"."t_invited_user"."f_status" IS '验证码状态 1:可用,2:不可用'; COMMENT ON COLUMN "public"."t_invited_user"."f_expired_at" IS '失效时间'; COMMENT ON COLUMN "public"."t_invited_user"."f_invited_id" IS '业务主键'; COMMENT ON COLUMN "public"."t_invited_user"."f_organization_id" IS '组织机构';


-- Primary Key structure for table t_invited_user


ALTER TABLE "public"."t_invited_user" ADD CONSTRAINT "t_invite_user_pkey" PRIMARY KEY ("f_id");

there is a diff in column f_id A use GENERATED ALWAYS when i delete the GENERATED ALWAYS flg ,the cmd can excute normally.

企业微信截图_be8720d4-45f8-4434-80b1-14f90ca40496
a8m commented 1 year ago

Hey @linyongzuo 👋

Thanks for reporting this. What version do you use?

linyongzuo commented 1 year ago

Hey @linyongzuo 👋

Thanks for reporting this. What version do you use?

the latest version 0.13.1 , postgresql version is 14.4

chenjpu commented 11 months ago

schema inspect

column "id" {
    null    = false
    type    = bigint
    default = sql("unique_rowid()")
  }

executing "schema_diff" at <sql $>: error calling sql: reverse alter table "xxxx": unexpected attribute change (expect IDENTITY): []