-
Notifications
You must be signed in to change notification settings - Fork 56
Added migration sql script: create project.templateId and new tables #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
coderReview
merged 2 commits into
topcoder-platform:feature/dev-challenges
from
ngoctay:feature/dev-challenges
Jun 10, 2018
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
315 changes: 315 additions & 0 deletions
315
migrations/20180608_project_add_templateId_and_new_tables.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,315 @@ | ||
-- | ||
-- UPDATE EXISTING TABLES: | ||
-- projects | ||
-- templateId column: added | ||
-- version column: added | ||
-- CREATE NEW TABLES: | ||
-- milestones | ||
-- phase_products | ||
-- product_milestone_templates | ||
-- product_templates | ||
-- project_phases | ||
-- project_templates | ||
-- project_types | ||
-- timelines | ||
-- | ||
|
||
-- | ||
-- projects | ||
-- | ||
ALTER TABLE projects ADD COLUMN "templateId" bigint; | ||
|
||
-- make sure to update existing projects to have this field set to "v2" | ||
ALTER TABLE projects ADD COLUMN "version" varchar(3) NOT NULL DEFAULT 'v2'; | ||
-- make sure new projects from now on have "v3" as default value | ||
ALTER TABLE projects ALTER COLUMN "version" SET DEFAULT 'v3'; | ||
|
||
-- | ||
-- milestones | ||
-- | ||
|
||
CREATE TABLE milestones ( | ||
id bigint NOT NULL, | ||
name character varying(255) NOT NULL, | ||
description character varying(255), | ||
duration integer NOT NULL, | ||
"startDate" timestamp with time zone NOT NULL, | ||
"endDate" timestamp with time zone, | ||
"completionDate" timestamp with time zone, | ||
status character varying(45) NOT NULL, | ||
type character varying(45) NOT NULL, | ||
details json, | ||
"order" integer NOT NULL, | ||
"plannedText" character varying(512) NOT NULL, | ||
"activeText" character varying(512) NOT NULL, | ||
"completedText" character varying(512) NOT NULL, | ||
"blockedText" character varying(512) NOT NULL, | ||
"deletedAt" timestamp with time zone, | ||
"createdAt" timestamp with time zone, | ||
"updatedAt" timestamp with time zone, | ||
"deletedBy" bigint, | ||
"createdBy" bigint NOT NULL, | ||
"updatedBy" bigint NOT NULL, | ||
"timelineId" bigint | ||
); | ||
|
||
CREATE SEQUENCE milestones_id_seq | ||
START WITH 1 | ||
INCREMENT BY 1 | ||
NO MINVALUE | ||
NO MAXVALUE | ||
CACHE 1; | ||
|
||
ALTER SEQUENCE milestones_id_seq OWNED BY milestones.id; | ||
|
||
|
||
-- | ||
-- phase_products | ||
-- | ||
|
||
CREATE TABLE phase_products ( | ||
id bigint NOT NULL, | ||
name character varying(255), | ||
"projectId" bigint, | ||
"directProjectId" bigint, | ||
"billingAccountId" bigint, | ||
"templateId" bigint DEFAULT 0, | ||
type character varying(255), | ||
"estimatedPrice" double precision DEFAULT 0, | ||
"actualPrice" double precision DEFAULT 0, | ||
details json DEFAULT '{}'::json, | ||
"deletedAt" timestamp with time zone, | ||
"createdAt" timestamp with time zone, | ||
"updatedAt" timestamp with time zone, | ||
"deletedBy" integer, | ||
"createdBy" integer NOT NULL, | ||
"updatedBy" integer NOT NULL, | ||
"phaseId" bigint | ||
); | ||
|
||
|
||
CREATE SEQUENCE phase_products_id_seq | ||
START WITH 1 | ||
INCREMENT BY 1 | ||
NO MINVALUE | ||
NO MAXVALUE | ||
CACHE 1; | ||
|
||
ALTER SEQUENCE phase_products_id_seq OWNED BY phase_products.id; | ||
|
||
-- | ||
-- product_milestone_templates | ||
-- | ||
|
||
CREATE TABLE product_milestone_templates ( | ||
id bigint NOT NULL, | ||
name character varying(255) NOT NULL, | ||
description character varying(255), | ||
duration integer NOT NULL, | ||
type character varying(45) NOT NULL, | ||
"order" integer NOT NULL, | ||
"deletedAt" timestamp with time zone, | ||
"createdAt" timestamp with time zone, | ||
"updatedAt" timestamp with time zone, | ||
"deletedBy" bigint, | ||
"createdBy" bigint NOT NULL, | ||
"updatedBy" bigint NOT NULL, | ||
"productTemplateId" bigint | ||
); | ||
|
||
CREATE SEQUENCE product_milestone_templates_id_seq | ||
START WITH 1 | ||
INCREMENT BY 1 | ||
NO MINVALUE | ||
NO MAXVALUE | ||
CACHE 1; | ||
|
||
ALTER SEQUENCE product_milestone_templates_id_seq OWNED BY product_milestone_templates.id; | ||
|
||
|
||
-- | ||
-- product_templates | ||
-- | ||
CREATE TABLE product_templates ( | ||
id bigint NOT NULL, | ||
name character varying(255) NOT NULL, | ||
"productKey" character varying(45) NOT NULL, | ||
icon character varying(255) NOT NULL, | ||
brief character varying(45) NOT NULL, | ||
details character varying(255) NOT NULL, | ||
aliases json NOT NULL, | ||
template json NOT NULL, | ||
"deletedAt" timestamp with time zone, | ||
"createdAt" timestamp with time zone, | ||
"updatedAt" timestamp with time zone, | ||
"deletedBy" bigint, | ||
"createdBy" bigint NOT NULL, | ||
"updatedBy" bigint NOT NULL | ||
); | ||
|
||
CREATE SEQUENCE product_templates_id_seq | ||
START WITH 1 | ||
INCREMENT BY 1 | ||
NO MINVALUE | ||
NO MAXVALUE | ||
CACHE 1; | ||
|
||
ALTER SEQUENCE product_templates_id_seq OWNED BY product_templates.id; | ||
|
||
-- | ||
-- project_phases | ||
-- | ||
|
||
CREATE TABLE project_phases ( | ||
id bigint NOT NULL, | ||
name character varying(255), | ||
status character varying(255), | ||
"startDate" timestamp with time zone, | ||
"endDate" timestamp with time zone, | ||
budget double precision DEFAULT 0, | ||
progress double precision DEFAULT 0, | ||
details json DEFAULT '{}'::json, | ||
"deletedAt" timestamp with time zone, | ||
"createdAt" timestamp with time zone, | ||
"updatedAt" timestamp with time zone, | ||
"deletedBy" integer, | ||
"createdBy" integer NOT NULL, | ||
"updatedBy" integer NOT NULL, | ||
"projectId" bigint | ||
); | ||
|
||
CREATE SEQUENCE project_phases_id_seq | ||
START WITH 1 | ||
INCREMENT BY 1 | ||
NO MINVALUE | ||
NO MAXVALUE | ||
CACHE 1; | ||
|
||
ALTER SEQUENCE project_phases_id_seq OWNED BY project_phases.id; | ||
|
||
|
||
-- | ||
-- project_templates | ||
-- | ||
CREATE TABLE project_templates ( | ||
id bigint NOT NULL, | ||
name character varying(255) NOT NULL, | ||
key character varying(45) NOT NULL, | ||
category character varying(45) NOT NULL, | ||
icon character varying(255) NOT NULL, | ||
question character varying(255) NOT NULL, | ||
info character varying(255) NOT NULL, | ||
aliases json NOT NULL, | ||
scope json NOT NULL, | ||
phases json NOT NULL, | ||
"deletedAt" timestamp with time zone, | ||
"createdAt" timestamp with time zone, | ||
"updatedAt" timestamp with time zone, | ||
"deletedBy" bigint, | ||
"createdBy" bigint NOT NULL, | ||
"updatedBy" bigint NOT NULL | ||
); | ||
|
||
CREATE SEQUENCE project_templates_id_seq | ||
START WITH 1 | ||
INCREMENT BY 1 | ||
NO MINVALUE | ||
NO MAXVALUE | ||
CACHE 1; | ||
|
||
ALTER SEQUENCE project_templates_id_seq OWNED BY project_templates.id; | ||
|
||
-- | ||
-- project_types | ||
-- | ||
|
||
CREATE TABLE project_types ( | ||
key character varying(45) NOT NULL, | ||
"displayName" character varying(255) NOT NULL, | ||
"deletedAt" timestamp with time zone, | ||
"createdAt" timestamp with time zone, | ||
"updatedAt" timestamp with time zone, | ||
"deletedBy" integer, | ||
"createdBy" integer NOT NULL, | ||
"updatedBy" integer NOT NULL | ||
); | ||
|
||
-- | ||
-- timelines | ||
-- | ||
CREATE TABLE timelines ( | ||
id bigint NOT NULL, | ||
name character varying(255) NOT NULL, | ||
description character varying(255), | ||
"startDate" timestamp with time zone NOT NULL, | ||
"endDate" timestamp with time zone, | ||
reference character varying(45) NOT NULL, | ||
"referenceId" bigint NOT NULL, | ||
"deletedAt" timestamp with time zone, | ||
"createdAt" timestamp with time zone, | ||
"updatedAt" timestamp with time zone, | ||
"deletedBy" bigint, | ||
"createdBy" bigint NOT NULL, | ||
"updatedBy" bigint NOT NULL | ||
); | ||
|
||
CREATE SEQUENCE timelines_id_seq | ||
START WITH 1 | ||
INCREMENT BY 1 | ||
NO MINVALUE | ||
NO MAXVALUE | ||
CACHE 1; | ||
|
||
ALTER SEQUENCE timelines_id_seq OWNED BY timelines.id; | ||
|
||
|
||
ALTER TABLE ONLY milestones ALTER COLUMN id SET DEFAULT nextval('milestones_id_seq'::regclass); | ||
|
||
ALTER TABLE ONLY phase_products ALTER COLUMN id SET DEFAULT nextval('phase_products_id_seq'::regclass); | ||
|
||
ALTER TABLE ONLY product_milestone_templates ALTER COLUMN id SET DEFAULT nextval('product_milestone_templates_id_seq'::regclass); | ||
|
||
ALTER TABLE ONLY product_templates ALTER COLUMN id SET DEFAULT nextval('product_templates_id_seq'::regclass); | ||
|
||
ALTER TABLE ONLY project_phases ALTER COLUMN id SET DEFAULT nextval('project_phases_id_seq'::regclass); | ||
|
||
ALTER TABLE ONLY project_templates ALTER COLUMN id SET DEFAULT nextval('project_templates_id_seq'::regclass); | ||
|
||
ALTER TABLE ONLY timelines ALTER COLUMN id SET DEFAULT nextval('timelines_id_seq'::regclass); | ||
|
||
ALTER TABLE ONLY milestones | ||
ADD CONSTRAINT milestones_pkey PRIMARY KEY (id); | ||
|
||
ALTER TABLE ONLY phase_products | ||
ADD CONSTRAINT phase_products_pkey PRIMARY KEY (id); | ||
|
||
ALTER TABLE ONLY product_milestone_templates | ||
ADD CONSTRAINT product_milestone_templates_pkey PRIMARY KEY (id); | ||
|
||
ALTER TABLE ONLY product_templates | ||
ADD CONSTRAINT product_templates_pkey PRIMARY KEY (id); | ||
|
||
ALTER TABLE ONLY project_phases | ||
ADD CONSTRAINT project_phases_pkey PRIMARY KEY (id); | ||
|
||
ALTER TABLE ONLY project_templates | ||
ADD CONSTRAINT project_templates_pkey PRIMARY KEY (id); | ||
|
||
ALTER TABLE ONLY project_types | ||
ADD CONSTRAINT project_types_pkey PRIMARY KEY (key); | ||
|
||
ALTER TABLE ONLY timelines | ||
ADD CONSTRAINT timelines_pkey PRIMARY KEY (id); | ||
|
||
ALTER TABLE ONLY milestones | ||
ADD CONSTRAINT "milestones_timelineId_fkey" FOREIGN KEY ("timelineId") REFERENCES timelines(id) ON UPDATE CASCADE ON DELETE CASCADE; | ||
|
||
ALTER TABLE ONLY phase_products | ||
ADD CONSTRAINT "phase_products_phaseId_fkey" FOREIGN KEY ("phaseId") REFERENCES project_phases(id) ON UPDATE CASCADE ON DELETE SET NULL; | ||
|
||
|
||
ALTER TABLE ONLY product_milestone_templates | ||
ADD CONSTRAINT "product_milestone_templates_productTemplateId_fkey" FOREIGN KEY ("productTemplateId") REFERENCES product_templates(id) ON UPDATE CASCADE ON DELETE CASCADE; | ||
|
||
ALTER TABLE ONLY project_phases | ||
ADD CONSTRAINT "project_phases_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES projects(id) ON UPDATE CASCADE ON DELETE SET NULL; |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about version column with default value v2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about that column.
I found it in another script: https://github.com/topcoder-platform/tc-project-service/blob/feature/dev-challenges/migrations/project_add_version_column.sql
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to remove "project_add_version_column.sql", and add the "version" column into the new script?
If so, what is the default value? v2 or v3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vikasrohit is it ok to have two scripts to run on prod?
20180608_project_add_templateId_and_new_tables.sql
project_add_version_column.sql
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although it is okay to have multiple scripts, I would like single script for single release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ngoctay when running the scripts old records should have v2 values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ngoctay I think we can merge those 2 scripts into one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
56cafd1