From 80e3c0b2f5277cfab1d09dc30b9f2a259ecbdc21 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 23 Jan 2023 15:58:08 +0000 Subject: [PATCH] insights: remove deprecated dirty_queries table (#45714) --- internal/database/schema.codeinsights.json | 125 ------------------ internal/database/schema.codeinsights.md | 29 ---- .../down.sql | 27 ++++ .../metadata.yaml | 2 + .../up.sql | 1 + migrations/codeinsights/squashed.sql | 39 ------ 6 files changed, 30 insertions(+), 193 deletions(-) create mode 100644 migrations/codeinsights/1674474174_remove_dirty_queries_table/down.sql create mode 100644 migrations/codeinsights/1674474174_remove_dirty_queries_table/metadata.yaml create mode 100644 migrations/codeinsights/1674474174_remove_dirty_queries_table/up.sql diff --git a/internal/database/schema.codeinsights.json b/internal/database/schema.codeinsights.json index effcc0fb985..1577a633341 100755 --- a/internal/database/schema.codeinsights.json +++ b/internal/database/schema.codeinsights.json @@ -66,15 +66,6 @@ "Increment": 1, "CycleOption": "NO" }, - { - "Name": "insight_dirty_queries_id_seq", - "TypeName": "integer", - "StartValue": 1, - "MinimumValue": 1, - "MaximumValue": 2147483647, - "Increment": 1, - "CycleOption": "NO" - }, { "Name": "insight_series_backfill_id_seq", "TypeName": "integer", @@ -882,122 +873,6 @@ ], "Triggers": [] }, - { - "Name": "insight_dirty_queries", - "Comment": "Stores queries that were unsuccessful or otherwise flagged as incomplete or incorrect.", - "Columns": [ - { - "Name": "dirty_at", - "Index": 4, - "TypeName": "timestamp without time zone", - "IsNullable": false, - "Default": "CURRENT_TIMESTAMP", - "CharacterMaximumLength": 0, - "IsIdentity": false, - "IdentityGeneration": "", - "IsGenerated": "NEVER", - "GenerationExpression": "", - "Comment": "Timestamp when this query was marked dirty." - }, - { - "Name": "for_time", - "Index": 6, - "TypeName": "timestamp without time zone", - "IsNullable": false, - "Default": "", - "CharacterMaximumLength": 0, - "IsIdentity": false, - "IdentityGeneration": "", - "IsGenerated": "NEVER", - "GenerationExpression": "", - "Comment": "Timestamp for which the original data point was recorded or intended to be recorded." - }, - { - "Name": "id", - "Index": 1, - "TypeName": "integer", - "IsNullable": false, - "Default": "nextval('insight_dirty_queries_id_seq'::regclass)", - "CharacterMaximumLength": 0, - "IsIdentity": false, - "IdentityGeneration": "", - "IsGenerated": "NEVER", - "GenerationExpression": "", - "Comment": "" - }, - { - "Name": "insight_series_id", - "Index": 2, - "TypeName": "integer", - "IsNullable": true, - "Default": "", - "CharacterMaximumLength": 0, - "IsIdentity": false, - "IdentityGeneration": "", - "IsGenerated": "NEVER", - "GenerationExpression": "", - "Comment": "" - }, - { - "Name": "query", - "Index": 3, - "TypeName": "text", - "IsNullable": false, - "Default": "", - "CharacterMaximumLength": 0, - "IsIdentity": false, - "IdentityGeneration": "", - "IsGenerated": "NEVER", - "GenerationExpression": "", - "Comment": "Sourcegraph query string that was executed." - }, - { - "Name": "reason", - "Index": 5, - "TypeName": "text", - "IsNullable": false, - "Default": "", - "CharacterMaximumLength": 0, - "IsIdentity": false, - "IdentityGeneration": "", - "IsGenerated": "NEVER", - "GenerationExpression": "", - "Comment": "Human readable string indicating the reason the query was marked dirty." - } - ], - "Indexes": [ - { - "Name": "insight_dirty_queries_pkey", - "IsPrimaryKey": true, - "IsUnique": true, - "IsExclusion": false, - "IsDeferrable": false, - "IndexDefinition": "CREATE UNIQUE INDEX insight_dirty_queries_pkey ON insight_dirty_queries USING btree (id)", - "ConstraintType": "p", - "ConstraintDefinition": "PRIMARY KEY (id)" - }, - { - "Name": "insight_dirty_queries_insight_series_id_fk_idx", - "IsPrimaryKey": false, - "IsUnique": false, - "IsExclusion": false, - "IsDeferrable": false, - "IndexDefinition": "CREATE INDEX insight_dirty_queries_insight_series_id_fk_idx ON insight_dirty_queries USING btree (insight_series_id)", - "ConstraintType": "", - "ConstraintDefinition": "" - } - ], - "Constraints": [ - { - "Name": "insight_dirty_queries_insight_series_id_fkey", - "ConstraintType": "f", - "RefTableName": "insight_series", - "IsDeferrable": false, - "ConstraintDefinition": "FOREIGN KEY (insight_series_id) REFERENCES insight_series(id) ON DELETE CASCADE" - } - ], - "Triggers": [] - }, { "Name": "insight_series", "Comment": "Data series that comprise code insights.", diff --git a/internal/database/schema.codeinsights.md b/internal/database/schema.codeinsights.md index 8eae9704900..9d9c091e5c5 100755 --- a/internal/database/schema.codeinsights.md +++ b/internal/database/schema.codeinsights.md @@ -137,34 +137,6 @@ Foreign-key constraints: ``` -# Table "public.insight_dirty_queries" -``` - Column | Type | Collation | Nullable | Default --------------------+-----------------------------+-----------+----------+--------------------------------------------------- - id | integer | | not null | nextval('insight_dirty_queries_id_seq'::regclass) - insight_series_id | integer | | | - query | text | | not null | - dirty_at | timestamp without time zone | | not null | CURRENT_TIMESTAMP - reason | text | | not null | - for_time | timestamp without time zone | | not null | -Indexes: - "insight_dirty_queries_pkey" PRIMARY KEY, btree (id) - "insight_dirty_queries_insight_series_id_fk_idx" btree (insight_series_id) -Foreign-key constraints: - "insight_dirty_queries_insight_series_id_fkey" FOREIGN KEY (insight_series_id) REFERENCES insight_series(id) ON DELETE CASCADE - -``` - -Stores queries that were unsuccessful or otherwise flagged as incomplete or incorrect. - -**dirty_at**: Timestamp when this query was marked dirty. - -**for_time**: Timestamp for which the original data point was recorded or intended to be recorded. - -**query**: Sourcegraph query string that was executed. - -**reason**: Human readable string indicating the reason the query was marked dirty. - # Table "public.insight_series" ``` Column | Type | Collation | Nullable | Default @@ -198,7 +170,6 @@ Indexes: "insight_series_deleted_at_idx" btree (deleted_at) "insight_series_next_recording_after_idx" btree (next_recording_after) Referenced by: - TABLE "insight_dirty_queries" CONSTRAINT "insight_dirty_queries_insight_series_id_fkey" FOREIGN KEY (insight_series_id) REFERENCES insight_series(id) ON DELETE CASCADE TABLE "insight_series_backfill" CONSTRAINT "insight_series_backfill_series_id_fk" FOREIGN KEY (series_id) REFERENCES insight_series(id) ON DELETE CASCADE TABLE "archived_insight_series_recording_times" CONSTRAINT "insight_series_id_fkey" FOREIGN KEY (insight_series_id) REFERENCES insight_series(id) ON DELETE CASCADE TABLE "insight_series_recording_times" CONSTRAINT "insight_series_id_fkey" FOREIGN KEY (insight_series_id) REFERENCES insight_series(id) ON DELETE CASCADE diff --git a/migrations/codeinsights/1674474174_remove_dirty_queries_table/down.sql b/migrations/codeinsights/1674474174_remove_dirty_queries_table/down.sql new file mode 100644 index 00000000000..60d95eaff75 --- /dev/null +++ b/migrations/codeinsights/1674474174_remove_dirty_queries_table/down.sql @@ -0,0 +1,27 @@ +CREATE TABLE IF NOT EXISTS insight_dirty_queries ( + id integer PRIMARY KEY, + insight_series_id integer, + query text NOT NULL, + dirty_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, + reason text NOT NULL, + for_time timestamp without time zone NOT NULL +); + + +CREATE SEQUENCE IF NOT EXISTS insight_dirty_queries_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE IF EXISTS insight_dirty_queries_id_seq OWNED BY insight_dirty_queries.id; + +ALTER TABLE IF EXISTS insight_dirty_queries ALTER COLUMN id SET DEFAULT nextval('insight_dirty_queries_id_seq'::regclass); + +ALTER TABLE IF EXISTS insight_dirty_queries DROP CONSTRAINT IF EXISTS insight_dirty_queries_insight_series_id_fkey; +ALTER TABLE IF EXISTS insight_dirty_queries + ADD CONSTRAINT insight_dirty_queries_insight_series_id_fkey FOREIGN KEY (insight_series_id) REFERENCES insight_series(id) ON DELETE CASCADE; + +CREATE INDEX IF NOT EXISTS insight_dirty_queries_insight_series_id_fk_idx ON insight_dirty_queries USING btree (insight_series_id); \ No newline at end of file diff --git a/migrations/codeinsights/1674474174_remove_dirty_queries_table/metadata.yaml b/migrations/codeinsights/1674474174_remove_dirty_queries_table/metadata.yaml new file mode 100644 index 00000000000..e766a2c7473 --- /dev/null +++ b/migrations/codeinsights/1674474174_remove_dirty_queries_table/metadata.yaml @@ -0,0 +1,2 @@ +name: remove_dirty_queries_table +parents: [1672921606] diff --git a/migrations/codeinsights/1674474174_remove_dirty_queries_table/up.sql b/migrations/codeinsights/1674474174_remove_dirty_queries_table/up.sql new file mode 100644 index 00000000000..9b4707c5291 --- /dev/null +++ b/migrations/codeinsights/1674474174_remove_dirty_queries_table/up.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS insight_dirty_queries; \ No newline at end of file diff --git a/migrations/codeinsights/squashed.sql b/migrations/codeinsights/squashed.sql index 2a70480bffc..657d50805f2 100755 --- a/migrations/codeinsights/squashed.sql +++ b/migrations/codeinsights/squashed.sql @@ -138,35 +138,6 @@ CREATE SEQUENCE dashboard_insight_view_id_seq ALTER SEQUENCE dashboard_insight_view_id_seq OWNED BY dashboard_insight_view.id; -CREATE TABLE insight_dirty_queries ( - id integer NOT NULL, - insight_series_id integer, - query text NOT NULL, - dirty_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, - reason text NOT NULL, - for_time timestamp without time zone NOT NULL -); - -COMMENT ON TABLE insight_dirty_queries IS 'Stores queries that were unsuccessful or otherwise flagged as incomplete or incorrect.'; - -COMMENT ON COLUMN insight_dirty_queries.query IS 'Sourcegraph query string that was executed.'; - -COMMENT ON COLUMN insight_dirty_queries.dirty_at IS 'Timestamp when this query was marked dirty.'; - -COMMENT ON COLUMN insight_dirty_queries.reason IS 'Human readable string indicating the reason the query was marked dirty.'; - -COMMENT ON COLUMN insight_dirty_queries.for_time IS 'Timestamp for which the original data point was recorded or intended to be recorded.'; - -CREATE SEQUENCE insight_dirty_queries_id_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - -ALTER SEQUENCE insight_dirty_queries_id_seq OWNED BY insight_dirty_queries.id; - CREATE TABLE insight_series ( id integer NOT NULL, series_id text NOT NULL, @@ -581,8 +552,6 @@ ALTER TABLE ONLY dashboard_grants ALTER COLUMN id SET DEFAULT nextval('dashboard ALTER TABLE ONLY dashboard_insight_view ALTER COLUMN id SET DEFAULT nextval('dashboard_insight_view_id_seq'::regclass); -ALTER TABLE ONLY insight_dirty_queries ALTER COLUMN id SET DEFAULT nextval('insight_dirty_queries_id_seq'::regclass); - ALTER TABLE ONLY insight_series ALTER COLUMN id SET DEFAULT nextval('insight_series_id_seq'::regclass); ALTER TABLE ONLY insight_series_backfill ALTER COLUMN id SET DEFAULT nextval('insight_series_backfill_id_seq'::regclass); @@ -623,9 +592,6 @@ ALTER TABLE ONLY dashboard_insight_view ALTER TABLE ONLY dashboard ADD CONSTRAINT dashboard_pk PRIMARY KEY (id); -ALTER TABLE ONLY insight_dirty_queries - ADD CONSTRAINT insight_dirty_queries_pkey PRIMARY KEY (id); - ALTER TABLE ONLY insight_series_backfill ADD CONSTRAINT insight_series_backfill_pk PRIMARY KEY (id); @@ -682,8 +648,6 @@ CREATE INDEX dashboard_insight_view_dashboard_id_fk_idx ON dashboard_insight_vie CREATE INDEX dashboard_insight_view_insight_view_id_fk_idx ON dashboard_insight_view USING btree (insight_view_id); -CREATE INDEX insight_dirty_queries_insight_series_id_fk_idx ON insight_dirty_queries USING btree (insight_series_id); - CREATE INDEX insight_series_deleted_at_idx ON insight_series USING btree (deleted_at); CREATE UNIQUE INDEX insight_series_incomplete_points_unique_idx ON insight_series_incomplete_points USING btree (series_id, reason, "time", repo_id); @@ -743,9 +707,6 @@ ALTER TABLE ONLY dashboard_insight_view ALTER TABLE ONLY dashboard_insight_view ADD CONSTRAINT dashboard_insight_view_insight_view_id_fk FOREIGN KEY (insight_view_id) REFERENCES insight_view(id) ON DELETE CASCADE; -ALTER TABLE ONLY insight_dirty_queries - ADD CONSTRAINT insight_dirty_queries_insight_series_id_fkey FOREIGN KEY (insight_series_id) REFERENCES insight_series(id) ON DELETE CASCADE; - ALTER TABLE ONLY insight_series_backfill ADD CONSTRAINT insight_series_backfill_series_id_fk FOREIGN KEY (series_id) REFERENCES insight_series(id) ON DELETE CASCADE;