From ec3af0cad63e4256beb58a8c4eda888dd0aad54e Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Wed, 14 Nov 2018 18:34:03 +0100 Subject: [PATCH] Adding all migrations --- .../migrations/20181112_131638_testMig.go | 30 ---------------- .../20181114_181043_company_user.go | 35 +++++++++++++++++++ .../20181114_181913_company_data.go | 35 +++++++++++++++++++ database/migrations/20181114_181919_post.go | 35 +++++++++++++++++++ .../migrations/20181114_181923_contact.go | 35 +++++++++++++++++++ .../20181108_133717_initial_schema.go | 6 +++- 6 files changed, 145 insertions(+), 31 deletions(-) delete mode 100644 database/migrations/20181112_131638_testMig.go create mode 100644 database/migrations/20181114_181043_company_user.go create mode 100644 database/migrations/20181114_181913_company_data.go create mode 100644 database/migrations/20181114_181919_post.go create mode 100644 database/migrations/20181114_181923_contact.go diff --git a/database/migrations/20181112_131638_testMig.go b/database/migrations/20181112_131638_testMig.go deleted file mode 100644 index dfceccd..0000000 --- a/database/migrations/20181112_131638_testMig.go +++ /dev/null @@ -1,30 +0,0 @@ -package main - -import ( - "github.com/astaxie/beego/migration" -) - -// DO NOT MODIFY -type TestMig_20181112_131638 struct { - migration.Migration -} - -// DO NOT MODIFY -func init() { - m := &TestMig_20181112_131638{} - m.Created = "20181112_131638" - - migration.Register("TestMig_20181112_131638", m) -} - -// Run the migrations -func (m *TestMig_20181112_131638) Up() { - // use m.SQL("CREATE TABLE ...") to make schema update - -} - -// Reverse the migrations -func (m *TestMig_20181112_131638) Down() { - // use m.SQL("DROP TABLE ...") to reverse schema update - -} diff --git a/database/migrations/20181114_181043_company_user.go b/database/migrations/20181114_181043_company_user.go new file mode 100644 index 0000000..7a0b639 --- /dev/null +++ b/database/migrations/20181114_181043_company_user.go @@ -0,0 +1,35 @@ +package main + +import ( + "github.com/astaxie/beego/migration" +) + +// DO NOT MODIFY +type CompanyUser_20181114_181043 struct { + migration.Migration +} + +// DO NOT MODIFY +func init() { + m := &CompanyUser_20181114_181043{} + m.Created = "20181114_181043" + + migration.Register("CompanyUser_20181114_181043", m) +} + +// Run the migrations +func (m *CompanyUser_20181114_181043) Up() { + // use m.SQL("CREATE TABLE ...") to make schema update + m.SQL("CREATE TABLE public.company_user ( id integer NOT NULL, name text NOT NULL, role smallint NOT NULL, profile jsonb NOT NULL, created timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, modified timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL);") + m.SQL("CREATE SEQUENCE public.\"companyUser_id_seq\" AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;") + m.SQL("ALTER SEQUENCE public.\"companyUser_id_seq\" OWNED BY public.company_user.id;") + m.SQL("ALTER TABLE ONLY public.company_user ALTER COLUMN id SET DEFAULT nextval('public.\"companyUser_id_seq\"'::regclass);") + m.SQL("ALTER TABLE ONLY public.company_user ADD CONSTRAINT \"companyUser_pkey\" PRIMARY KEY (id);") + +} + +// Reverse the migrations +func (m *CompanyUser_20181114_181043) Down() { + m.SQL("DROP TABLE public.company_user;") + +} diff --git a/database/migrations/20181114_181913_company_data.go b/database/migrations/20181114_181913_company_data.go new file mode 100644 index 0000000..06548c6 --- /dev/null +++ b/database/migrations/20181114_181913_company_data.go @@ -0,0 +1,35 @@ +package main + +import ( + "github.com/astaxie/beego/migration" +) + +// DO NOT MODIFY +type CompanyData_20181114_181913 struct { + migration.Migration +} + +// DO NOT MODIFY +func init() { + m := &CompanyData_20181114_181913{} + m.Created = "20181114_181913" + + migration.Register("CompanyData_20181114_181913", m) +} + +// Run the migrations +func (m *CompanyData_20181114_181913) Up() { + // use m.SQL("CREATE TABLE ...") to make schema update + m.SQL("CREATE TABLE public.company_data ( id integer NOT NULL, key text NOT NULL, value text, data jsonb, created timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, modified timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL);") + m.SQL("CREATE SEQUENCE public.\"companyData_id_seq\" AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;") + m.SQL("ALTER SEQUENCE public.\"companyData_id_seq\" OWNED BY public.company_data.id;") + m.SQL("ALTER TABLE ONLY public.company_data ALTER COLUMN id SET DEFAULT nextval('public.\"companyData_id_seq\"'::regclass);") + m.SQL("ALTER TABLE ONLY public.company_data ADD CONSTRAINT \"companyData_pkey\" PRIMARY KEY (id);") +} + +// Reverse the migrations +func (m *CompanyData_20181114_181913) Down() { + // use m.SQL("DROP TABLE ...") to reverse schema update + m.SQL("DROP TABLE public.company_data;") + +} diff --git a/database/migrations/20181114_181919_post.go b/database/migrations/20181114_181919_post.go new file mode 100644 index 0000000..e30f507 --- /dev/null +++ b/database/migrations/20181114_181919_post.go @@ -0,0 +1,35 @@ +package main + +import ( + "github.com/astaxie/beego/migration" +) + +// DO NOT MODIFY +type Post_20181114_181919 struct { + migration.Migration +} + +// DO NOT MODIFY +func init() { + m := &Post_20181114_181919{} + m.Created = "20181114_181919" + + migration.Register("Post_20181114_181919", m) +} + +// Run the migrations +func (m *Post_20181114_181919) Up() { + // use m.SQL("CREATE TABLE ...") to make schema update + m.SQL("CREATE TABLE public.post ( id integer NOT NULL, name text, data text NOT NULL, meta jsonb NOT NULL, created timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, modified timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL);") + m.SQL("CREATE SEQUENCE public.post_id_seq AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;") + m.SQL("ALTER SEQUENCE public.post_id_seq OWNED BY public.post.id;") + m.SQL("ALTER TABLE ONLY public.post ALTER COLUMN id SET DEFAULT nextval('public.post_id_seq'::regclass);") + m.SQL("ALTER TABLE ONLY public.post ADD CONSTRAINT post_pkey PRIMARY KEY (id);") +} + +// Reverse the migrations +func (m *Post_20181114_181919) Down() { + // use m.SQL("DROP TABLE ...") to reverse schema update + m.SQL("DROP TABLE public.post;") + +} diff --git a/database/migrations/20181114_181923_contact.go b/database/migrations/20181114_181923_contact.go new file mode 100644 index 0000000..b48dfa4 --- /dev/null +++ b/database/migrations/20181114_181923_contact.go @@ -0,0 +1,35 @@ +package main + +import ( + "github.com/astaxie/beego/migration" +) + +// DO NOT MODIFY +type Contact_20181114_181923 struct { + migration.Migration +} + +// DO NOT MODIFY +func init() { + m := &Contact_20181114_181923{} + m.Created = "20181114_181923" + + migration.Register("Contact_20181114_181923", m) +} + +// Run the migrations +func (m *Contact_20181114_181923) Up() { + // use m.SQL("CREATE TABLE ...") to make schema update + m.SQL("CREATE TABLE public.contact ( id integer NOT NULL, \"firstName\" text, \"lastName\" text NOT NULL, \"phoneNumber\" text, email text, \"lastContact\" date, meta jsonb NOT NULL, created timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, modified timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL);") + m.SQL("CREATE SEQUENCE public.contact_id_seq AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;") + m.SQL("ALTER SEQUENCE public.contact_id_seq OWNED BY public.contact.id;") + m.SQL("ALTER TABLE ONLY public.contact ALTER COLUMN id SET DEFAULT nextval('public.contact_id_seq'::regclass);") + m.SQL("ALTER TABLE ONLY public.contact ADD CONSTRAINT contact_pkey PRIMARY KEY (id);") +} + +// Reverse the migrations +func (m *Contact_20181114_181923) Down() { + // use m.SQL("DROP TABLE ...") to reverse schema update + m.SQL("DROP TABLE public.contact;") + +} diff --git a/database/systemmigrations/20181108_133717_initial_schema.go b/database/systemmigrations/20181108_133717_initial_schema.go index 07cea06..34b6988 100644 --- a/database/systemmigrations/20181108_133717_initial_schema.go +++ b/database/systemmigrations/20181108_133717_initial_schema.go @@ -21,10 +21,14 @@ func init() { func (m *InitialSchema_20181108_133717) Up() { // use m.SQL("CREATE TABLE ...") to make schema update m.SQL("CREATE TABLE public.user_company_map (id integer NOT NULL,email text NOT NULL,password_hash text NOT NULL,company text NOT NULL,company_user_id bigint NOT NULL,created timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,modified timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL);") + m.SQL("CREATE SEQUENCE public.system_users_id_seq AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;") + m.SQL("ALTER SEQUENCE public.system_users_id_seq OWNED BY public.user_company_map.id;") + m.SQL("ALTER TABLE ONLY public.user_company_map ALTER COLUMN id SET DEFAULT nextval('public.system_users_id_seq'::regclass);") + m.SQL("ALTER TABLE ONLY public.user_company_map ADD CONSTRAINT system_users_pkey PRIMARY KEY (id);") } // Reverse the migrations func (m *InitialSchema_20181108_133717) Down() { // use m.SQL("DROP TABLE ...") to reverse schema update - m.SQL("DROP TABLE uer_company_map;") + m.SQL("DROP TABLE user_company_map;") }