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 TABLE public.cms_user_unit_seq OWNER TO postgres;

SELECT pg_catalog.setval('cms_user_unit_seq', 1, false);

CREATE 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 TABLE public.cms_user_unit OWNER TO postgres;
ALTER TABLE public.cms_user_unit ADD PRIMARY KEY ("user_unit_id");


COMMENT ON TABLE public.cms_user_unit IS '我是关联表';
COMMENT ON COLUMN public.cms_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 where tt.control_unit_id = tt1.unit_id and tt1.unit_type=1);

posted @ 2017-01-11 19:19  人生如若初见  阅读(539)  评论(0编辑  收藏  举报