Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Add watchdog submissions DB table migration SQL. (#4376) (#4417)
Browse files Browse the repository at this point in the history
- And the new 'abuse', 'usererror', and 'watchdog' block types. (#4347)
  • Loading branch information
chenba authored and jaredhirsch committed May 31, 2018
1 parent 17daa57 commit 513693e
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 4 deletions.
9 changes: 9 additions & 0 deletions server/db-patches/patch-22-23.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- pg-patcher runs migrations in transactions. However, ALTER TYPE ... ADD VALUE
-- cannot be executed inside a transaction block. We will swap out the enum type
-- with a new one instead.
ALTER TYPE shot_block_type RENAME TO old_shot_block_type;
CREATE TYPE shot_block_type AS ENUM ('none', 'dmca', 'abuse', 'usererror', 'watchdog');
ALTER TABLE data ALTER COLUMN block_type DROP DEFAULT;
ALTER TABLE data ALTER COLUMN block_type TYPE shot_block_type USING block_type::text::shot_block_type;
ALTER TABLE data ALTER COLUMN block_type SET DEFAULT 'none'::shot_block_type;
DROP TYPE old_shot_block_type;
4 changes: 4 additions & 0 deletions server/db-patches/patch-23-22.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Records using the new enum values from 22-23 must be updated or deleted in
-- order to update the enum type. Moreover, the entire `data` table must be
-- updated to use a new enum type (see 22-23 for what's entailed).
-- For those reasons, we refrain from removing the enum values in here.
12 changes: 12 additions & 0 deletions server/db-patches/patch-23-24.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CREATE TABLE watchdog_submissions (
id SERIAL,
shot_id CHARACTER VARYING(270) NOT NULL,
request_id CHARACTER(36) NOT NULL,
nonce CHARACTER(36) NOT NULL,
positive_result boolean,
CONSTRAINT watchdog_pkey PRIMARY KEY (id),
CONSTRAINT watchdog_shot_id_fkey FOREIGN KEY (shot_id)
REFERENCES data(id)
ON UPDATE NO ACTION
ON DELETE CASCADE
);
1 change: 1 addition & 0 deletions server/db-patches/patch-24-23.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE watchdog_submissions;
27 changes: 24 additions & 3 deletions server/schema.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
CREATE TYPE shot_block_type AS ENUM (
'none',
'dmca'
'dmca',
'abuse',
'usererror',
'watchdog'
);
ALTER TYPE shot_block_type OWNER TO ianbicking;
CREATE TABLE accounts (
id character varying(200) NOT NULL,
token text,
Expand Down Expand Up @@ -58,6 +60,21 @@ CREATE TABLE states (
state character varying(64) NOT NULL,
deviceid character varying(200)
);
CREATE TABLE watchdog_submissions (
id integer NOT NULL,
shot_id character varying(270) NOT NULL,
request_id character(36) NOT NULL,
nonce character(36) NOT NULL,
positive_result boolean
);
CREATE SEQUENCE watchdog_submissions_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE watchdog_submissions_id_seq OWNED BY watchdog_submissions.id;
ALTER TABLE ONLY watchdog_submissions ALTER COLUMN id SET DEFAULT nextval('watchdog_submissions_id_seq'::regclass);
ALTER TABLE ONLY accounts
ADD CONSTRAINT accounts_pkey PRIMARY KEY (id);
ALTER TABLE ONLY data
Expand All @@ -70,6 +87,8 @@ ALTER TABLE ONLY property
ADD CONSTRAINT property_pkey PRIMARY KEY (key);
ALTER TABLE ONLY states
ADD CONSTRAINT states_pkey PRIMARY KEY (state);
ALTER TABLE ONLY watchdog_submissions
ADD CONSTRAINT watchdog_pkey PRIMARY KEY (id);
CREATE INDEX data_deviceid_idx ON data USING btree (deviceid);
CREATE INDEX devices_accountid_idx ON devices USING btree (accountid);
CREATE INDEX images_shotid_idx ON images USING btree (shotid);
Expand All @@ -83,4 +102,6 @@ ALTER TABLE ONLY images
ADD CONSTRAINT images_shotid_fkey FOREIGN KEY (shotid) REFERENCES data(id) ON DELETE CASCADE;
ALTER TABLE ONLY states
ADD CONSTRAINT states_deviceid_fkey FOREIGN KEY (deviceid) REFERENCES devices(id) ON DELETE CASCADE;
-- pg-patch version: 20
ALTER TABLE ONLY watchdog_submissions
ADD CONSTRAINT watchdog_shot_id_fkey FOREIGN KEY (shot_id) REFERENCES data(id) ON DELETE CASCADE;
-- pg-patch version: 24
2 changes: 1 addition & 1 deletion server/src/dbschema.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const mozlog = require("./logging").mozlog("dbschema");

// When updating the database, please also run ./bin/dumpschema --record
// This updates schema.sql with the latest full database schema
const MAX_DB_LEVEL = exports.MAX_DB_LEVEL = 22;
const MAX_DB_LEVEL = exports.MAX_DB_LEVEL = 24;

exports.forceDbVersion = function(version) {
mozlog.info("forcing-db-version", {db: db.constr, version});
Expand Down

0 comments on commit 513693e

Please sign in to comment.