Skip to content

Commit

Permalink
feat: run migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
KagChi committed May 10, 2024
1 parent ccf76a0 commit fd72089
Show file tree
Hide file tree
Showing 13 changed files with 2,822 additions and 10 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ COPY --from=build-stage /tmp/build/package.json .
COPY --from=build-stage /tmp/build/pnpm-lock.yaml .
COPY --from=build-stage /tmp/build/node_modules ./node_modules
COPY --from=build-stage /tmp/build/dist ./dist
COPY --from=build-stage /tmp/build/drizzle ./drizzle

CMD node dist/index.js
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

<img src="https://i.kagchi.my.id/nezuko.png" alt="Logo" width="200px" height="200px" style="border-radius:50%"/>

# @nezuchan/template
# @nezuchan/postgrestify

**A TypeScript template project.**
**The standalone postgres proxy for drizzle.**

[![GitHub](https://img.shields.io/github/license/nezuchan/cordis-brokers)](https://github.com/nezuchan/cordis-brokers/blob/main/LICENSE)
[![GitHub](https://img.shields.io/github/license/nezuchan/postgrestify)](https://github.com/nezuchan/postgrestify/blob/main/LICENSE)
[![Discord](https://discordapp.com/api/guilds/785715968608567297/embed.png)](https://nezu.my.id)

</div>
11 changes: 11 additions & 0 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import process from "node:process";
import type { Config } from "drizzle-kit";

export default {
dialect: "postgresql",
schema: "./node_modules/@nezuchan/schema/dist/index.js",
out: "./drizzle",
dbCredentials: {
url: process.env.DATABASE_URL!
}
} satisfies Config;
104 changes: 104 additions & 0 deletions drizzle/0000_premium_leo.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
DO $$ BEGIN
CREATE TYPE "TierType" AS ENUM('FREE', 'SUPPORTER', 'TIER_1', 'TIER_2', 'TIER_3');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "activation_key" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"tier" "TierType" DEFAULT 'FREE',
"provider" text,
"guild_id" uuid,
"client_id" text,
"start_at" timestamp,
"ends_at" timestamp,
"key" text,
"user_id" uuid,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "crossfade" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"guild_id" uuid,
"client_id" text,
"activated_by" text,
"state" boolean DEFAULT false,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "default_volume" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"guild_id" uuid,
"client_id" text,
"activated_by" text,
"state" integer DEFAULT 100,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "guild" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"guild_id" text,
"client_id" text,
"key_id" text,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "stay_in_vc" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"guild_id" uuid,
"client_id" text,
"activated_by" text,
"state" boolean DEFAULT false,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "user" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"email" text,
"discord_id" text,
"patreon_id" text,
"premium_provider" text DEFAULT 'UNKNOWN',
"premium_tier" "TierType" DEFAULT 'FREE',
"premium_start_at" timestamp DEFAULT now(),
"premium_ends_at" timestamp,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp NOT NULL,
"voted_at" timestamp,
CONSTRAINT "user_discord_id_unique" UNIQUE("discord_id"),
CONSTRAINT "user_patreon_id_unique" UNIQUE("patreon_id")
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "activation_key" ADD CONSTRAINT "activation_key_guild_id_guild_id_fk" FOREIGN KEY ("guild_id") REFERENCES "guild"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "activation_key" ADD CONSTRAINT "activation_key_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "crossfade" ADD CONSTRAINT "crossfade_guild_id_guild_id_fk" FOREIGN KEY ("guild_id") REFERENCES "guild"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "default_volume" ADD CONSTRAINT "default_volume_guild_id_guild_id_fk" FOREIGN KEY ("guild_id") REFERENCES "guild"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "stay_in_vc" ADD CONSTRAINT "stay_in_vc_guild_id_guild_id_fk" FOREIGN KEY ("guild_id") REFERENCES "guild"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
32 changes: 32 additions & 0 deletions drizzle/0001_parched_ikaris.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
DO $$ BEGIN
CREATE TYPE "Visibility" AS ENUM('PUBLIC', 'PRIVATE');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "playlist" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"external_id" text,
"user_id" text,
"name" text,
"visibility" "Visibility",
"track_limit" integer,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "playlist_track" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"playlist_id" uuid,
"external_id" text,
"user_id" text,
"track" json,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp NOT NULL
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "playlist_track" ADD CONSTRAINT "playlist_track_playlist_id_playlist_id_fk" FOREIGN KEY ("playlist_id") REFERENCES "playlist"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
2 changes: 2 additions & 0 deletions drizzle/0002_nappy_valkyrie.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE "playlist" ALTER COLUMN "visibility" SET DEFAULT 'PUBLIC';--> statement-breakpoint
ALTER TABLE "playlist" ALTER COLUMN "track_limit" SET DEFAULT 20;
Loading

0 comments on commit fd72089

Please sign in to comment.