Postgres数据库补丁脚本⽰例
SET client_encoding = 'UTF8';
-- 新建序列和表
DROP TABLE IF EXISTS cms_user_unit;
DROP SEQUENCE IF EXISTS cms_user_unit_seq CASCADE ;
CREATE SEQUENCE cms_user_unit_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER s_user_unit_seq OWNER TO postgres;
SELECT pg_catalog.setval('cms_user_unit_seq', 1, false);
drop table if exists userCREATE TABLE cms_user_unit (
user_unit_id integer DEFAULT nextval('cms_user_unit_seq'::regclass) NOT NULL,
user_id integer NOT NULL,
unit_id integer NOT NULL,
unit_type smallint NOT NULL,
cre_id integer,
cre_time timestamp,
upd_id integer,
upd_time timestamp,
is_delete smallint
);
ALTER s_user_unit OWNER TO postgres;
ALTER s_user_unit ADD PRIMARY KEY ("user_unit_id");
COMMENT ON s_user_unit IS '我是关联表';
COMMENT ON s_user_unit.unit_id IS '我是列的中⽂名';
--增加初始化数据
insert into cms_user_unit(user_unit_id,user_id, unit_id,unit_type,cre_id,cre_time,upd_id,upd_time,is_delete) select nextval('cms_user_unit_seq'),1, control_unit_id,1,4,null,4,null,0 from s_control_unit tt
where parent_id = 0
and not exists (select unit_id from cms_user_unit tt1 l_unit_id = tt1.unit_id and tt1.unit_t
ype=1);

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。