Skip to content

Commit

Permalink
prepare for launch
Browse files Browse the repository at this point in the history
  • Loading branch information
benjick committed Sep 21, 2024
1 parent f0ed358 commit 13b60d9
Show file tree
Hide file tree
Showing 19 changed files with 600 additions and 60 deletions.
8 changes: 0 additions & 8 deletions .docker/config/config.yml

This file was deleted.

17 changes: 0 additions & 17 deletions .docker/sonarr/config.xml

This file was deleted.

3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
./config.yml
.docker
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
node_modules
dist
.docker/postgres
.docker
/config.yml
.env
.env.test
Expand Down
20 changes: 3 additions & 17 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ services:
- NODE_ENV=production
- DATABASE_URL=postgresql://postgres:postgres@db:5432/postgres
- CONFIG_PATH=/config/config.yml
- DEBUG=true
- SKIP_MIGRATIONS=true
# - DEBUG=true
volumes:
- .docker/config:/config
- ./config.yml:/config/config.yml
restart: unless-stopped

db:
image: postgres:13-alpine
image: postgres:16-alpine
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
Expand All @@ -26,18 +25,5 @@ services:
- postgres_data:/var/lib/postgresql/data
restart: unless-stopped

sonarr:
image: lscr.io/linuxserver/sonarr:latest
container_name: sonarr
environment:
- PUID=1000
- PGID=1000
- TZ=Etc/UTC
volumes:
- .docker/sonarr/config.xml:/config/config.xml:rw
ports:
- 8989:8989
restart: unless-stopped

volumes:
postgres_data:
16 changes: 9 additions & 7 deletions src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ export const db = drizzle(client, {
},
});

async function main() {
export async function runMigrations() {
if (env.NODE_ENV === "production") {
// Run migrations when deployed
if (env.SKIP_MIGRATIONS) {
console.log("🙈 Skipping migrations");
return;
}
const migrationClient = postgres(env.DATABASE_URL);
const db = drizzle(migrationClient);
console.log("Running migrations...");
await migrate(db, { migrationsFolder: "./src/server/db/migrations" });
console.log("🔨 Running migrations...");
await migrate(db, { migrationsFolder: "./src/db/migrations" });
await migrationClient.end();
console.log("Migrations complete!");
console.log("✅ Migrations complete!");
} else {
console.log(
"🏃‍♂️ Skipping migrations in dev mode - run manually with 'pnpm db:push'",
);
}
}

void main();
83 changes: 83 additions & 0 deletions src/db/migrations/0000_dry_sage.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
DO $$ BEGIN
CREATE TYPE "public"."manager_type" AS ENUM('radarr', 'sonarr');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "public"."vote_outcome" AS ENUM('keep', 'delete');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "media_items" (
"id" varchar PRIMARY KEY NOT NULL,
"manager_id" integer NOT NULL,
"manager_type" "manager_type" NOT NULL,
"manager_config_id" varchar NOT NULL,
"title" varchar NOT NULL,
"size_on_disk" numeric DEFAULT '0' NOT NULL,
"release_date" timestamp NOT NULL,
"year" integer,
"has_file" boolean DEFAULT false,
"imdb_id" varchar,
"tmdb_id" integer,
"rating" real,
"added_to_manager" timestamp NOT NULL,
"path_on_disk" varchar,
"image" varchar,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now(),
CONSTRAINT "media_items_manager_id_manager_config_id_unique" UNIQUE("manager_id","manager_config_id")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "subscribers" (
"discord_user_id" varchar PRIMARY KEY NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "items_to_delete" (
"id" varchar PRIMARY KEY NOT NULL,
"delete_after" timestamp NOT NULL,
"deleted_at" timestamp,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "voting_sessions" (
"id" varchar PRIMARY KEY NOT NULL,
"discord_message_id" varchar NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"ends_at" timestamp NOT NULL,
"handled" boolean DEFAULT false NOT NULL,
"vote_outcome" "vote_outcome"
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "whitelist" (
"id" varchar PRIMARY KEY NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "items_to_delete" ADD CONSTRAINT "items_to_delete_id_media_items_id_fk" FOREIGN KEY ("id") REFERENCES "public"."media_items"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "voting_sessions" ADD CONSTRAINT "voting_sessions_id_media_items_id_fk" FOREIGN KEY ("id") REFERENCES "public"."media_items"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "whitelist" ADD CONSTRAINT "whitelist_id_media_items_id_fk" FOREIGN KEY ("id") REFERENCES "public"."media_items"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "manager_id_idx" ON "media_items" USING btree ("manager_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "manager_type_idx" ON "media_items" USING btree ("manager_type");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "manager_config_id_idx" ON "media_items" USING btree ("manager_config_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "added_to_manager_idx" ON "media_items" USING btree ("added_to_manager");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "discord_message_id_idx" ON "voting_sessions" USING btree ("discord_message_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "handled_idx" ON "voting_sessions" USING btree ("handled");
Loading

0 comments on commit 13b60d9

Please sign in to comment.