Migration for all the model changes for Project Templates
Description
This will create 2 new models, ProjectTemplate and ProjectTemplateOptions. These models will be used to store settings across multiple projects. This PR also creates a 1 to 1 relationship for ProjectTemplates and Projects.
Design Document: https://www.notion.so/sentry/Service-Settings-Templates-ca6fdb38b15f4a6db61d319bc342b86c?pvs=4#60623e7fbaba4e0985f8d4581af18e64
This PR has a migration; here is the generated SQL for src/sentry/migrations/0709_project_template_models.py ()
--
-- Create model ProjectTemplate
--
CREATE TABLE "sentry_projecttemplate" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "date_updated" timestamp with time zone NOT NULL, "date_added" timestamp with time zone NULL, "name" varchar(200) NOT NULL, "organization_id" bigint NOT NULL);
ALTER TABLE "sentry_projecttemplate" ADD CONSTRAINT "sentry_projecttempla_organization_id_b072f5c6_fk_sentry_or" FOREIGN KEY ("organization_id") REFERENCES "sentry_organization" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_projecttemplate" VALIDATE CONSTRAINT "sentry_projecttempla_organization_id_b072f5c6_fk_sentry_or";
CREATE INDEX CONCURRENTLY "sentry_projecttemplate_organization_id_b072f5c6" ON "sentry_projecttemplate" ("organization_id");
--
-- Add field template to project
--
ALTER TABLE "sentry_project" ADD COLUMN "template_id" bigint NULL;
--
-- Create model ProjectTemplateOption
--
CREATE TABLE "sentry_projecttemplateoption" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "key" varchar(64) NOT NULL, "value" text NOT NULL, "project_template_id" bigint NOT NULL);
ALTER TABLE "sentry_project" ADD CONSTRAINT "sentry_project_template_id_67f0bec7_fk_sentry_pr" FOREIGN KEY ("template_id") REFERENCES "sentry_projecttemplate" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_project" VALIDATE CONSTRAINT "sentry_project_template_id_67f0bec7_fk_sentry_pr";
CREATE INDEX CONCURRENTLY "sentry_project_template_id_67f0bec7" ON "sentry_project" ("template_id");
ALTER TABLE "sentry_projecttemplateoption" ADD CONSTRAINT "sentry_projecttempla_project_template_id_23fa7e71_fk_sentry_pr" FOREIGN KEY ("project_template_id") REFERENCES "sentry_projecttemplate" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_projecttemplateoption" VALIDATE CONSTRAINT "sentry_projecttempla_project_template_id_23fa7e71_fk_sentry_pr";
CREATE INDEX CONCURRENTLY "sentry_projecttemplateoption_project_template_id_23fa7e71" ON "sentry_projecttemplateoption" ("project_template_id");
--
-- Create constraint unique_projecttemplate_name_per_org on model projecttemplate
--
CREATE UNIQUE INDEX CONCURRENTLY "unique_projecttemplate_name_per_org" ON "sentry_projecttemplate" ("name", "organization_id");
ALTER TABLE "sentry_projecttemplate" ADD CONSTRAINT "unique_projecttemplate_name_per_org" UNIQUE USING INDEX "unique_projecttemplate_name_per_org";
--
-- Alter unique_together for projecttemplateoption (1 constraint(s))
--
CREATE UNIQUE INDEX CONCURRENTLY "sentry_projecttemplateop_project_template_id_key_87ae3e18_uniq" ON "sentry_projecttemplateoption" ("project_template_id", "key");
ALTER TABLE "sentry_projecttemplateoption" ADD CONSTRAINT "sentry_projecttemplateop_project_template_id_key_87ae3e18_uniq" UNIQUE USING INDEX "sentry_projecttemplateop_project_template_id_key_87ae3e18_uniq";
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 77.91%. Comparing base (
7fbe058) to head (fe5a369). Report is 46 commits behind head on master.
Additional details and impacted files
@@ Coverage Diff @@
## master #69816 +/- ##
===========================================
+ Coverage 61.13% 77.91% +16.77%
===========================================
Files 6508 6514 +6
Lines 290081 290367 +286
Branches 50202 50245 +43
===========================================
+ Hits 177341 226227 +48886
+ Misses 106971 57848 -49123
- Partials 5769 6292 +523
| Files | Coverage Δ | |
|---|---|---|
| src/sentry/backup/comparators.py | 95.36% <ø> (+19.13%) |
:arrow_up: |
| src/sentry/models/__init__.py | 100.00% <100.00%> (ø) |
|
| src/sentry/models/options/__init__.py | 100.00% <100.00%> (ø) |
|
| ...c/sentry/models/options/project_template_option.py | 100.00% <100.00%> (ø) |
|
| src/sentry/models/project.py | 94.70% <100.00%> (+15.96%) |
:arrow_up: |
| src/sentry/models/projecttemplate.py | 100.00% <100.00%> (ø) |
|
| src/sentry/testutils/helpers/backups.py | 99.41% <100.00%> (+2.66%) |
:arrow_up: |
This PR has a migration; here is the generated SQL for src/sentry/migrations/0710_project_template_models.py ()
--
-- Create model ProjectTemplate
--
CREATE TABLE "sentry_projecttemplate" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "date_updated" timestamp with time zone NOT NULL, "date_added" timestamp with time zone NULL, "name" varchar(200) NOT NULL, "organization_id" bigint NOT NULL);
ALTER TABLE "sentry_projecttemplate" ADD CONSTRAINT "sentry_projecttempla_organization_id_b072f5c6_fk_sentry_or" FOREIGN KEY ("organization_id") REFERENCES "sentry_organization" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_projecttemplate" VALIDATE CONSTRAINT "sentry_projecttempla_organization_id_b072f5c6_fk_sentry_or";
CREATE INDEX CONCURRENTLY "sentry_projecttemplate_organization_id_b072f5c6" ON "sentry_projecttemplate" ("organization_id");
--
-- Add field template to project
--
ALTER TABLE "sentry_project" ADD COLUMN "template_id" bigint NULL;
--
-- Create model ProjectTemplateOption
--
CREATE TABLE "sentry_projecttemplateoption" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "key" varchar(64) NOT NULL, "value" text NOT NULL, "project_template_id" bigint NOT NULL);
ALTER TABLE "sentry_project" ADD CONSTRAINT "sentry_project_template_id_67f0bec7_fk_sentry_pr" FOREIGN KEY ("template_id") REFERENCES "sentry_projecttemplate" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_project" VALIDATE CONSTRAINT "sentry_project_template_id_67f0bec7_fk_sentry_pr";
CREATE INDEX CONCURRENTLY "sentry_project_template_id_67f0bec7" ON "sentry_project" ("template_id");
ALTER TABLE "sentry_projecttemplateoption" ADD CONSTRAINT "sentry_projecttempla_project_template_id_23fa7e71_fk_sentry_pr" FOREIGN KEY ("project_template_id") REFERENCES "sentry_projecttemplate" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_projecttemplateoption" VALIDATE CONSTRAINT "sentry_projecttempla_project_template_id_23fa7e71_fk_sentry_pr";
CREATE INDEX CONCURRENTLY "sentry_projecttemplateoption_project_template_id_23fa7e71" ON "sentry_projecttemplateoption" ("project_template_id");
--
-- Create constraint unique_projecttemplate_name_per_org on model projecttemplate
--
CREATE UNIQUE INDEX CONCURRENTLY "unique_projecttemplate_name_per_org" ON "sentry_projecttemplate" ("name", "organization_id");
ALTER TABLE "sentry_projecttemplate" ADD CONSTRAINT "unique_projecttemplate_name_per_org" UNIQUE USING INDEX "unique_projecttemplate_name_per_org";
--
-- Alter unique_together for projecttemplateoption (1 constraint(s))
--
CREATE UNIQUE INDEX CONCURRENTLY "sentry_projecttemplateop_project_template_id_key_87ae3e18_uniq" ON "sentry_projecttemplateoption" ("project_template_id", "key");
ALTER TABLE "sentry_projecttemplateoption" ADD CONSTRAINT "sentry_projecttemplateop_project_template_id_key_87ae3e18_uniq" UNIQUE USING INDEX "sentry_projecttemplateop_project_template_id_key_87ae3e18_uniq";
This PR has a migration; here is the generated SQL for src/sentry/migrations/0714_project_template_models.py ()
--
-- Create model ProjectTemplate
--
CREATE TABLE "sentry_projecttemplate" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "date_updated" timestamp with time zone NOT NULL, "date_added" timestamp with time zone NULL, "name" varchar(200) NOT NULL, "organization_id" bigint NOT NULL);
ALTER TABLE "sentry_projecttemplate" ADD CONSTRAINT "sentry_projecttempla_organization_id_b072f5c6_fk_sentry_or" FOREIGN KEY ("organization_id") REFERENCES "sentry_organization" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_projecttemplate" VALIDATE CONSTRAINT "sentry_projecttempla_organization_id_b072f5c6_fk_sentry_or";
CREATE INDEX CONCURRENTLY "sentry_projecttemplate_organization_id_b072f5c6" ON "sentry_projecttemplate" ("organization_id");
--
-- Add field template to project
--
ALTER TABLE "sentry_project" ADD COLUMN "template_id" bigint NULL;
--
-- Create model ProjectTemplateOption
--
CREATE TABLE "sentry_projecttemplateoption" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "key" varchar(64) NOT NULL, "value" text NOT NULL, "project_template_id" bigint NOT NULL);
ALTER TABLE "sentry_project" ADD CONSTRAINT "sentry_project_template_id_67f0bec7_fk_sentry_pr" FOREIGN KEY ("template_id") REFERENCES "sentry_projecttemplate" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_project" VALIDATE CONSTRAINT "sentry_project_template_id_67f0bec7_fk_sentry_pr";
CREATE INDEX CONCURRENTLY "sentry_project_template_id_67f0bec7" ON "sentry_project" ("template_id");
ALTER TABLE "sentry_projecttemplateoption" ADD CONSTRAINT "sentry_projecttempla_project_template_id_23fa7e71_fk_sentry_pr" FOREIGN KEY ("project_template_id") REFERENCES "sentry_projecttemplate" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_projecttemplateoption" VALIDATE CONSTRAINT "sentry_projecttempla_project_template_id_23fa7e71_fk_sentry_pr";
CREATE INDEX CONCURRENTLY "sentry_projecttemplateoption_project_template_id_23fa7e71" ON "sentry_projecttemplateoption" ("project_template_id");
--
-- Create constraint unique_projecttemplate_name_per_org on model projecttemplate
--
CREATE UNIQUE INDEX CONCURRENTLY "unique_projecttemplate_name_per_org" ON "sentry_projecttemplate" ("name", "organization_id");
ALTER TABLE "sentry_projecttemplate" ADD CONSTRAINT "unique_projecttemplate_name_per_org" UNIQUE USING INDEX "unique_projecttemplate_name_per_org";
--
-- Alter unique_together for projecttemplateoption (1 constraint(s))
--
CREATE UNIQUE INDEX CONCURRENTLY "sentry_projecttemplateop_project_template_id_key_87ae3e18_uniq" ON "sentry_projecttemplateoption" ("project_template_id", "key");
ALTER TABLE "sentry_projecttemplateoption" ADD CONSTRAINT "sentry_projecttemplateop_project_template_id_key_87ae3e18_uniq" UNIQUE USING INDEX "sentry_projecttemplateop_project_template_id_key_87ae3e18_uniq";
This PR has a migration; here is the generated SQL for src/sentry/migrations/0715_project_template_models.py ()
--
-- Create model ProjectTemplate
--
CREATE TABLE "sentry_projecttemplate" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "date_updated" timestamp with time zone NOT NULL, "date_added" timestamp with time zone NULL, "name" varchar(200) NOT NULL, "organization_id" bigint NOT NULL);
ALTER TABLE "sentry_projecttemplate" ADD CONSTRAINT "sentry_projecttempla_organization_id_b072f5c6_fk_sentry_or" FOREIGN KEY ("organization_id") REFERENCES "sentry_organization" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_projecttemplate" VALIDATE CONSTRAINT "sentry_projecttempla_organization_id_b072f5c6_fk_sentry_or";
CREATE INDEX CONCURRENTLY "sentry_projecttemplate_organization_id_b072f5c6" ON "sentry_projecttemplate" ("organization_id");
--
-- Add field template to project
--
ALTER TABLE "sentry_project" ADD COLUMN "template_id" bigint NULL;
--
-- Create model ProjectTemplateOption
--
CREATE TABLE "sentry_projecttemplateoption" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "key" varchar(64) NOT NULL, "value" text NOT NULL, "project_template_id" bigint NOT NULL);
ALTER TABLE "sentry_project" ADD CONSTRAINT "sentry_project_template_id_67f0bec7_fk_sentry_pr" FOREIGN KEY ("template_id") REFERENCES "sentry_projecttemplate" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_project" VALIDATE CONSTRAINT "sentry_project_template_id_67f0bec7_fk_sentry_pr";
CREATE INDEX CONCURRENTLY "sentry_project_template_id_67f0bec7" ON "sentry_project" ("template_id");
ALTER TABLE "sentry_projecttemplateoption" ADD CONSTRAINT "sentry_projecttempla_project_template_id_23fa7e71_fk_sentry_pr" FOREIGN KEY ("project_template_id") REFERENCES "sentry_projecttemplate" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_projecttemplateoption" VALIDATE CONSTRAINT "sentry_projecttempla_project_template_id_23fa7e71_fk_sentry_pr";
CREATE INDEX CONCURRENTLY "sentry_projecttemplateoption_project_template_id_23fa7e71" ON "sentry_projecttemplateoption" ("project_template_id");
--
-- Create constraint unique_projecttemplate_name_per_org on model projecttemplate
--
CREATE UNIQUE INDEX CONCURRENTLY "unique_projecttemplate_name_per_org" ON "sentry_projecttemplate" ("name", "organization_id");
ALTER TABLE "sentry_projecttemplate" ADD CONSTRAINT "unique_projecttemplate_name_per_org" UNIQUE USING INDEX "unique_projecttemplate_name_per_org";
--
-- Alter unique_together for projecttemplateoption (1 constraint(s))
--
CREATE UNIQUE INDEX CONCURRENTLY "sentry_projecttemplateop_project_template_id_key_87ae3e18_uniq" ON "sentry_projecttemplateoption" ("project_template_id", "key");
ALTER TABLE "sentry_projecttemplateoption" ADD CONSTRAINT "sentry_projecttemplateop_project_template_id_key_87ae3e18_uniq" UNIQUE USING INDEX "sentry_projecttemplateop_project_template_id_key_87ae3e18_uniq";
This PR has a migration; here is the generated SQL for src/sentry/migrations/0723_project_template_models.py ()
--
-- Create model ProjectTemplate
--
CREATE TABLE "sentry_projecttemplate" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "date_updated" timestamp with time zone NOT NULL, "date_added" timestamp with time zone NULL, "name" varchar(200) NOT NULL, "organization_id" bigint NOT NULL);
ALTER TABLE "sentry_projecttemplate" ADD CONSTRAINT "sentry_projecttempla_organization_id_b072f5c6_fk_sentry_or" FOREIGN KEY ("organization_id") REFERENCES "sentry_organization" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_projecttemplate" VALIDATE CONSTRAINT "sentry_projecttempla_organization_id_b072f5c6_fk_sentry_or";
CREATE INDEX CONCURRENTLY "sentry_projecttemplate_organization_id_b072f5c6" ON "sentry_projecttemplate" ("organization_id");
--
-- Add field template to project
--
ALTER TABLE "sentry_project" ADD COLUMN "template_id" bigint NULL;
--
-- Create model ProjectTemplateOption
--
CREATE TABLE "sentry_projecttemplateoption" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "key" varchar(64) NOT NULL, "value" text NOT NULL, "project_template_id" bigint NOT NULL);
ALTER TABLE "sentry_project" ADD CONSTRAINT "sentry_project_template_id_67f0bec7_fk_sentry_pr" FOREIGN KEY ("template_id") REFERENCES "sentry_projecttemplate" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_project" VALIDATE CONSTRAINT "sentry_project_template_id_67f0bec7_fk_sentry_pr";
CREATE INDEX CONCURRENTLY "sentry_project_template_id_67f0bec7" ON "sentry_project" ("template_id");
ALTER TABLE "sentry_projecttemplateoption" ADD CONSTRAINT "sentry_projecttempla_project_template_id_23fa7e71_fk_sentry_pr" FOREIGN KEY ("project_template_id") REFERENCES "sentry_projecttemplate" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_projecttemplateoption" VALIDATE CONSTRAINT "sentry_projecttempla_project_template_id_23fa7e71_fk_sentry_pr";
CREATE INDEX CONCURRENTLY "sentry_projecttemplateoption_project_template_id_23fa7e71" ON "sentry_projecttemplateoption" ("project_template_id");
--
-- Create constraint unique_projecttemplate_name_per_org on model projecttemplate
--
CREATE UNIQUE INDEX CONCURRENTLY "unique_projecttemplate_name_per_org" ON "sentry_projecttemplate" ("name", "organization_id");
ALTER TABLE "sentry_projecttemplate" ADD CONSTRAINT "unique_projecttemplate_name_per_org" UNIQUE USING INDEX "unique_projecttemplate_name_per_org";
--
-- Alter unique_together for projecttemplateoption (1 constraint(s))
--
CREATE UNIQUE INDEX CONCURRENTLY "sentry_projecttemplateop_project_template_id_key_87ae3e18_uniq" ON "sentry_projecttemplateoption" ("project_template_id", "key");
ALTER TABLE "sentry_projecttemplateoption" ADD CONSTRAINT "sentry_projecttemplateop_project_template_id_key_87ae3e18_uniq" UNIQUE USING INDEX "sentry_projecttemplateop_project_template_id_key_87ae3e18_uniq";