From f7eb63ae73f8a26285bb5f36f609e19854a9213e Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Fri, 13 Sep 2024 23:56:49 +0530 Subject: [PATCH] feat(seeds): insert default tags into review tags table (#153) --- .../migrations/0009_luxuriant_purifiers.sql | 1 + server/db/migrations/meta/0009_snapshot.json | 371 ++++++++++++++++++ server/db/migrations/meta/_journal.json | 7 + server/db/schema.ts | 2 +- server/utils/seeds.ts | 21 +- shared/schemas/review-tags.ts | 2 +- 6 files changed, 400 insertions(+), 4 deletions(-) create mode 100644 server/db/migrations/0009_luxuriant_purifiers.sql create mode 100644 server/db/migrations/meta/0009_snapshot.json diff --git a/server/db/migrations/0009_luxuriant_purifiers.sql b/server/db/migrations/0009_luxuriant_purifiers.sql new file mode 100644 index 0000000..8d68242 --- /dev/null +++ b/server/db/migrations/0009_luxuriant_purifiers.sql @@ -0,0 +1 @@ +ALTER TABLE "review_tags" ALTER COLUMN "title" SET DATA TYPE varchar(32); \ No newline at end of file diff --git a/server/db/migrations/meta/0009_snapshot.json b/server/db/migrations/meta/0009_snapshot.json new file mode 100644 index 0000000..7584320 --- /dev/null +++ b/server/db/migrations/meta/0009_snapshot.json @@ -0,0 +1,371 @@ +{ + "id": "1c9c0011-c57e-4840-ab36-a39bb4ba0e5c", + "prevId": "36dac6d2-f744-494c-9e0c-652d8efceccf", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.hooks": { + "name": "hooks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(40)", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "prefs": { + "name": "prefs", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_executed_at": { + "name": "last_executed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.job_postings": { + "name": "job_postings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(150)", + "primaryKey": false, + "notNull": true + }, + "contents": { + "name": "contents", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tags_csv": { + "name": "tags_csv", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "owner_id": { + "name": "owner_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "is_published": { + "name": "is_published", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "total_applicants": { + "name": "total_applicants", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "job_postings_owner_id_users_id_fk": { + "name": "job_postings_owner_id_users_id_fk", + "tableFrom": "job_postings", + "tableTo": "users", + "columnsFrom": ["owner_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.metadata_entries": { + "name": "metadata_entries", + "schema": "", + "columns": { + "key": { + "name": "key", + "type": "varchar(48)", + "primaryKey": true, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.posting_applicants": { + "name": "posting_applicants", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "owner_id": { + "name": "owner_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "job_id": { + "name": "job_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "posting_applicants_owner_id_users_id_fk": { + "name": "posting_applicants_owner_id_users_id_fk", + "tableFrom": "posting_applicants", + "tableTo": "users", + "columnsFrom": ["owner_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "posting_applicants_job_id_job_postings_id_fk": { + "name": "posting_applicants_job_id_job_postings_id_fk", + "tableFrom": "posting_applicants", + "tableTo": "job_postings", + "columnsFrom": ["job_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.review_tags": { + "name": "review_tags", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "parent": { + "name": "parent", + "type": "smallint", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.user_handles": { + "name": "user_handles", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "key": { + "name": "key", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "user_handles_user_id_users_id_fk": { + "name": "user_handles_user_id_users_id_fk", + "tableFrom": "user_handles", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "first_name": { + "name": "first_name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "last_name": { + "name": "last_name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "picture": { + "name": "picture", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "permission": { + "name": "permission", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "top_5_skills_csv": { + "name": "top_5_skills_csv", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_admin": { + "name": "is_admin", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": ["email"] + } + } + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} diff --git a/server/db/migrations/meta/_journal.json b/server/db/migrations/meta/_journal.json index c427250..f5b14d7 100644 --- a/server/db/migrations/meta/_journal.json +++ b/server/db/migrations/meta/_journal.json @@ -64,6 +64,13 @@ "when": 1726152541712, "tag": "0008_open_quentin_quire", "breakpoints": true + }, + { + "idx": 9, + "version": "7", + "when": 1726223608639, + "tag": "0009_luxuriant_purifiers", + "breakpoints": true } ] } diff --git a/server/db/schema.ts b/server/db/schema.ts index 2142350..9b29df0 100644 --- a/server/db/schema.ts +++ b/server/db/schema.ts @@ -77,7 +77,7 @@ export type PostingApplication = typeof postingApplicantsTable.$inferSelect; export const reviewTagsTable = pgTable('review_tags', { id: defaultSerialPkField(), - title: varchar('title', { length: 8 }).notNull(), + title: varchar('title', { length: 32 }).notNull(), parent: smallint('parent').notNull(), }); diff --git a/server/utils/seeds.ts b/server/utils/seeds.ts index a6f5371..1105871 100644 --- a/server/utils/seeds.ts +++ b/server/utils/seeds.ts @@ -1,4 +1,4 @@ -import { metaDataTable } from '../db/schema'; +import { metaDataTable, reviewTagsTable } from '../db/schema'; /** * Seed 1 @@ -34,4 +34,21 @@ const seed2: SeedFn = async (ctx, payload) => { ]); }; -export const seeds = [seed1, seed2]; +/** + * Seeds 3 + * (Initialise review tags) + */ + +const seed3: SeedFn = async (ctx, _) => { + const db = ctx.db; + + await db.insert(reviewTagsTable).values([ + { title: 'Approved', parent: 4 }, + { title: 'Shortlisted', parent: 3 }, + { title: 'Rejected', parent: 2 }, + { title: 'Deferred', parent: 1 }, + { title: 'Pending', parent: 0 }, + ]); +}; + +export const seeds = [seed1, seed2, seed3]; diff --git a/shared/schemas/review-tags.ts b/shared/schemas/review-tags.ts index bb52356..b2592ff 100644 --- a/shared/schemas/review-tags.ts +++ b/shared/schemas/review-tags.ts @@ -2,7 +2,7 @@ import { z } from 'zod'; export const reviewTagSchema = z.object({ id: z.number().int().positive(), - title: z.string().max(8), + title: z.string().max(32), parent: z.number().int().min(0).max(4), });