From c89638262fd58d52635b3a3ccf5ab833218be8f7 Mon Sep 17 00:00:00 2001 From: Arthur DANJOU Date: Mon, 2 Sep 2024 16:58:43 +0200 Subject: [PATCH] Working --- .../migrations/0000_cloudy_lifeguard.sql | 63 ++++ .../migrations/meta/0000_snapshot.json | 329 ++++++++++++++++++ server/database/migrations/meta/_journal.json | 13 + 3 files changed, 405 insertions(+) create mode 100644 server/database/migrations/0000_cloudy_lifeguard.sql create mode 100644 server/database/migrations/meta/0000_snapshot.json create mode 100644 server/database/migrations/meta/_journal.json diff --git a/server/database/migrations/0000_cloudy_lifeguard.sql b/server/database/migrations/0000_cloudy_lifeguard.sql new file mode 100644 index 0000000..ab37d0c --- /dev/null +++ b/server/database/migrations/0000_cloudy_lifeguard.sql @@ -0,0 +1,63 @@ +DO $$ BEGIN + CREATE TYPE "public"."subscription" AS ENUM('free', 'paid'); +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "categories" ( + "id" serial PRIMARY KEY NOT NULL, + "name" text DEFAULT '', + "name_visible" boolean DEFAULT true, + "icon" text DEFAULT 'i-ph:circle-wavy-question-duotone', + "color" text DEFAULT 'gray', + "user_id" integer NOT NULL, + "created_at" timestamp (3) DEFAULT now(), + "updated_at" timestamp (3) +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "tabs" ( + "id" serial PRIMARY KEY NOT NULL, + "name" text DEFAULT '', + "primary" boolean DEFAULT false, + "icon" text DEFAULT 'i-ph:circle-wavy-question-duotone', + "color" text DEFAULT 'gray', + "link" text DEFAULT '', + "category_id" integer NOT NULL, + "created_at" timestamp (3) DEFAULT now(), + "updated_at" timestamp (3) +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "users" ( + "id" serial PRIMARY KEY NOT NULL, + "username" text NOT NULL, + "name" text NOT NULL, + "email" text NOT NULL, + "github_id" text, + "github_token" text, + "google_id" text, + "google_token" text, + "description" text DEFAULT '', + "avatar" text DEFAULT '', + "private" boolean DEFAULT false, + "language" text DEFAULT 'en-EN', + "location" text DEFAULT 'unknown', + "subscription" "subscription" DEFAULT 'free', + "created_at" timestamp (3) DEFAULT now(), + "updated_at" timestamp (3), + CONSTRAINT "users_username_unique" UNIQUE("username"), + CONSTRAINT "users_email_unique" UNIQUE("email"), + CONSTRAINT "users_github_id_unique" UNIQUE("github_id"), + CONSTRAINT "users_google_id_unique" UNIQUE("google_id") +); +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "categories" ADD CONSTRAINT "categories_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "tabs" ADD CONSTRAINT "tabs_category_id_categories_id_fk" FOREIGN KEY ("category_id") REFERENCES "public"."categories"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; diff --git a/server/database/migrations/meta/0000_snapshot.json b/server/database/migrations/meta/0000_snapshot.json new file mode 100644 index 0000000..065134c --- /dev/null +++ b/server/database/migrations/meta/0000_snapshot.json @@ -0,0 +1,329 @@ +{ + "id": "37cfa6b0-d0e9-4999-9ead-06b419388528", + "prevId": "00000000-0000-0000-0000-000000000000", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.categories": { + "name": "categories", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "name_visible": { + "name": "name_visible", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'i-ph:circle-wavy-question-duotone'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'gray'" + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp (3)", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (3)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "categories_user_id_users_id_fk": { + "name": "categories_user_id_users_id_fk", + "tableFrom": "categories", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.tabs": { + "name": "tabs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "primary": { + "name": "primary", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'i-ph:circle-wavy-question-duotone'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'gray'" + }, + "link": { + "name": "link", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "category_id": { + "name": "category_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp (3)", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (3)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "tabs_category_id_categories_id_fk": { + "name": "tabs_category_id_categories_id_fk", + "tableFrom": "tabs", + "tableTo": "categories", + "columnsFrom": [ + "category_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "github_id": { + "name": "github_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "github_token": { + "name": "github_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "google_id": { + "name": "google_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "google_token": { + "name": "google_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "avatar": { + "name": "avatar", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "private": { + "name": "private", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "language": { + "name": "language", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'en-EN'" + }, + "location": { + "name": "location", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'unknown'" + }, + "subscription": { + "name": "subscription", + "type": "subscription", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'free'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp (3)", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (3)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_username_unique": { + "name": "users_username_unique", + "nullsNotDistinct": false, + "columns": [ + "username" + ] + }, + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + }, + "users_github_id_unique": { + "name": "users_github_id_unique", + "nullsNotDistinct": false, + "columns": [ + "github_id" + ] + }, + "users_google_id_unique": { + "name": "users_google_id_unique", + "nullsNotDistinct": false, + "columns": [ + "google_id" + ] + } + } + } + }, + "enums": { + "public.subscription": { + "name": "subscription", + "schema": "public", + "values": [ + "free", + "paid" + ] + } + }, + "schemas": {}, + "sequences": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/server/database/migrations/meta/_journal.json b/server/database/migrations/meta/_journal.json new file mode 100644 index 0000000..921715d --- /dev/null +++ b/server/database/migrations/meta/_journal.json @@ -0,0 +1,13 @@ +{ + "version": "7", + "dialect": "postgresql", + "entries": [ + { + "idx": 0, + "version": "7", + "when": 1725282814515, + "tag": "0000_cloudy_lifeguard", + "breakpoints": true + } + ] +} \ No newline at end of file