Skip to content

Commit

Permalink
migration file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Thompson committed Dec 11, 2024
1 parent 4f5ac1c commit 3e04044
Showing 1 changed file with 40 additions and 69 deletions.
109 changes: 40 additions & 69 deletions database/src/migrations/20241211104011_support_markdown.ts
Original file line number Diff line number Diff line change
@@ -1,87 +1,58 @@
import { Knex } from 'knex';

/**
* Add tables to store versioned text displayed in help dialogs. Versions can be up-scored or down-scored by users.
* Adds multiple new markdown_type records, then adds new markdown records using a join on markdown_type.
*
* @export
* @param {Knex} knex
* @return {*} {Promise<void>}
*/
export async function up(knex: Knex): Promise<void> {
await knex.raw(`--sql
await knex.raw(`
SET SEARCH_PATH=biohub, public;
----------------------------------------------------------------------------------------
-- Create markdown_type table
-- Insert into markdown_type
----------------------------------------------------------------------------------------
CREATE TABLE markdown_type (
markdown_type_id integer GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1),
name varchar(25) NOT NULL,
description varchar(400) NOT NULL,
record_end_date date,
create_date timestamptz(6) DEFAULT now() NOT NULL,
create_user integer NOT NULL,
update_date timestamptz(6),
update_user integer,
revision_count integer DEFAULT 0 NOT NULL,
CONSTRAINT markdown_type_pk PRIMARY KEY (markdown_type_id)
);
----------------------------------------------------------------------------------------
-- Create markdown table
----------------------------------------------------------------------------------------
CREATE TABLE markdown (
markdown_id integer GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1),
markdown_type_id integer NOT NULL,
data varchar NOT NULL,
score integer DEFAULT 0 NOT NULL,
record_end_date date,
create_date timestamptz(6) DEFAULT now() NOT NULL,
create_user integer NOT NULL,
update_date timestamptz(6),
update_user integer,
revision_count integer DEFAULT 0 NOT NULL,
CONSTRAINT markdown_pk PRIMARY KEY (markdown_id)
);
----------------------------------------------------------------------------------------
-- Create table for tracking which users have scored on markdown records (only 1 score per user)
----------------------------------------------------------------------------------------
CREATE TABLE markdown_user (
markdown_user_id integer GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1),
system_user_id integer NOT NULL,
markdown_id integer NOT NULL,
create_date timestamptz(6) DEFAULT now() NOT NULL,
create_user integer NOT NULL,
update_date timestamptz(6),
update_user integer,
revision_count integer DEFAULT 0 NOT NULL,
CONSTRAINT markdown_user_pk PRIMARY KEY (markdown_user_id)
);
----------------------------------------------------------------------------------------
-- Insert markdown for dialogs
----------------------------------------------------------------------------------------
INSERT INTO
markdown_type (name, description)
VALUES
('supportGeneral', 'Help text about Support pages'),
('supportTelemetry', 'Help text regarding telemetry'),
(supportTelemtryBulk, 'Help text for telemtry bulk upload');
INSERT INTO
markdown (markdown_type_id, data)
INSERT INTO markdown_type (name, description)
VALUES
(1, '## Projects and Surveys\n\nProjects and Surveys let you organize and manage access to data.\n\n##### Projects\nProjects are folders containing information that is only accessible to the Project team.\n- All Projects you have created or been invited to will appear in your Projects list.\n- If you need access to an existing Project, your collaborator can invite you.\n\n##### Surveys\nSurveys let you organize ecological data collected in the field.\n- When adding new data, you can create a new Survey or add to an existing Survey.');
('Animal Support', 'Description for Type A'),
('Type B', 'Description for Type B'),
('Type C', 'Description for Type C'),
('Type D', 'Description for Type D'),
('Type E', 'Description for Type E'),
('Type F', 'Description for Type F'),
('Type G', 'Description for Type G'),
('Type H', 'Description for Type H'),
('Type I', 'Description for Type I'),
('Type J', 'Description for Type J');
----------------------------------------------------------------------------------------
-- Insert into markdown by selecting markdown_type_id based on markdown_type.name
----------------------------------------------------------------------------------------
INSERT INTO markdown (markdown_type_id, data)
SELECT
mt.markdown_type_id,
md.data
FROM
(VALUES
('Type A', '## Type A Content\\n\\nThis is some markdown content for Type A.'),
('Type B', '## Type B Content\\n\\nThis is some markdown content for Type B.'),
('Type C', '## Type C Content\\n\\nThis is some markdown content for Type C.'),
('Type D', '## Type D Content\\n\\nThis is some markdown content for Type D.'),
('Type E', '## Type E Content\\n\\nThis is some markdown content for Type E.'),
('Type F', '## Type F Content\\n\\nThis is some markdown content for Type F.'),
('Type G', '## Type G Content\\n\\nThis is some markdown content for Type G.'),
('Type H', '## Type H Content\\n\\nThis is some markdown content for Type H.'),
('Type I', '## Type I Content\\n\\nThis is some markdown content for Type I.'),
('Type J', '## Type J Content\\n\\nThis is some markdown content for Type J.')
) AS md(name, data)
JOIN
markdown_type mt ON mt.name = md.name;
`);
}

export async function down(knex: Knex): Promise<void> {
await knex.raw(``);
}
await knex.raw(``);
}

0 comments on commit 3e04044

Please sign in to comment.