-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(database): init database define
- Loading branch information
Showing
13 changed files
with
445 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { Config } from 'drizzle-kit'; | ||
|
||
import 'dotenv/config'; | ||
|
||
export default { | ||
schema: './src/schema/', | ||
out: './drizzle', | ||
driver: 'pg', | ||
dbCredentials: { | ||
host: process.env.DB_HOST!, | ||
database: process.env.DB_NAME!, | ||
user: process.env.DB_USER, | ||
password: process.env.DB_PASSWORD | ||
} | ||
} satisfies Config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
DO $$ BEGIN | ||
CREATE TYPE "resources_provider" AS ENUM('dmhy', 'moe'); | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
CREATE TABLE IF NOT EXISTS "resources" ( | ||
"id" serial PRIMARY KEY NOT NULL, | ||
"provider_type" "resources_provider" NOT NULL, | ||
"provider_id" varchar(256) NOT NULL, | ||
"href" varchar(256) NOT NULL, | ||
"title" varchar(256) NOT NULL, | ||
"title_alt" varchar(256) NOT NULL, | ||
"type" varchar(256) NOT NULL, | ||
"size" varchar(256) NOT NULL, | ||
"magnet" varchar(256) NOT NULL, | ||
"created_at" timestamp with time zone DEFAULT now(), | ||
"fetched_at" timestamp with time zone DEFAULT now(), | ||
"anitomy" json, | ||
"fansub_id" integer NOT NULL, | ||
"publisher_id" integer, | ||
"is_deleted" boolean DEFAULT false, | ||
"is_duplicated" boolean DEFAULT false | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE IF NOT EXISTS "teams" ( | ||
"id" serial PRIMARY KEY NOT NULL, | ||
"provider_type" "resources_provider" NOT NULL, | ||
"provider_id" varchar(256) NOT NULL, | ||
"name" varchar(256) NOT NULL | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE IF NOT EXISTS "users" ( | ||
"id" serial PRIMARY KEY NOT NULL, | ||
"provider_type" "resources_provider" NOT NULL, | ||
"provider_id" varchar(256) NOT NULL, | ||
"name" varchar(256) NOT NULL | ||
); | ||
--> statement-breakpoint | ||
CREATE UNIQUE INDEX IF NOT EXISTS "provider_type_id" ON "resources" ("provider_type","provider_id");--> statement-breakpoint | ||
CREATE INDEX IF NOT EXISTS "sort_by_created_at" ON "resources" ("created_at");--> statement-breakpoint | ||
CREATE INDEX IF NOT EXISTS "fansub_index" ON "resources" ("fansub_id");--> statement-breakpoint | ||
CREATE INDEX IF NOT EXISTS "publisher_index" ON "resources" ("publisher_id");--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "resources" ADD CONSTRAINT "resources_fansub_id_teams_id_fk" FOREIGN KEY ("fansub_id") REFERENCES "public"."teams"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "resources" ADD CONSTRAINT "resources_publisher_id_users_id_fk" FOREIGN KEY ("publisher_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,260 @@ | ||
{ | ||
"id": "be0483f5-b846-4d0b-86dc-95a86593343c", | ||
"prevId": "00000000-0000-0000-0000-000000000000", | ||
"version": "5", | ||
"dialect": "pg", | ||
"tables": { | ||
"resources": { | ||
"name": "resources", | ||
"schema": "", | ||
"columns": { | ||
"id": { | ||
"name": "id", | ||
"type": "serial", | ||
"primaryKey": true, | ||
"notNull": true | ||
}, | ||
"provider_type": { | ||
"name": "provider_type", | ||
"type": "resources_provider", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"provider_id": { | ||
"name": "provider_id", | ||
"type": "varchar(256)", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"href": { | ||
"name": "href", | ||
"type": "varchar(256)", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"title": { | ||
"name": "title", | ||
"type": "varchar(256)", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"title_alt": { | ||
"name": "title_alt", | ||
"type": "varchar(256)", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"type": { | ||
"name": "type", | ||
"type": "varchar(256)", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"size": { | ||
"name": "size", | ||
"type": "varchar(256)", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"magnet": { | ||
"name": "magnet", | ||
"type": "varchar(256)", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"created_at": { | ||
"name": "created_at", | ||
"type": "timestamp with time zone", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"default": "now()" | ||
}, | ||
"fetched_at": { | ||
"name": "fetched_at", | ||
"type": "timestamp with time zone", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"default": "now()" | ||
}, | ||
"anitomy": { | ||
"name": "anitomy", | ||
"type": "json", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"fansub_id": { | ||
"name": "fansub_id", | ||
"type": "integer", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"publisher_id": { | ||
"name": "publisher_id", | ||
"type": "integer", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"is_deleted": { | ||
"name": "is_deleted", | ||
"type": "boolean", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"default": false | ||
}, | ||
"is_duplicated": { | ||
"name": "is_duplicated", | ||
"type": "boolean", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"default": false | ||
} | ||
}, | ||
"indexes": { | ||
"provider_type_id": { | ||
"name": "provider_type_id", | ||
"columns": [ | ||
"provider_type", | ||
"provider_id" | ||
], | ||
"isUnique": true | ||
}, | ||
"sort_by_created_at": { | ||
"name": "sort_by_created_at", | ||
"columns": [ | ||
"created_at" | ||
], | ||
"isUnique": false | ||
}, | ||
"fansub_index": { | ||
"name": "fansub_index", | ||
"columns": [ | ||
"fansub_id" | ||
], | ||
"isUnique": false | ||
}, | ||
"publisher_index": { | ||
"name": "publisher_index", | ||
"columns": [ | ||
"publisher_id" | ||
], | ||
"isUnique": false | ||
} | ||
}, | ||
"foreignKeys": { | ||
"resources_fansub_id_teams_id_fk": { | ||
"name": "resources_fansub_id_teams_id_fk", | ||
"tableFrom": "resources", | ||
"tableTo": "teams", | ||
"schemaTo": "public", | ||
"columnsFrom": [ | ||
"fansub_id" | ||
], | ||
"columnsTo": [ | ||
"id" | ||
], | ||
"onDelete": "no action", | ||
"onUpdate": "no action" | ||
}, | ||
"resources_publisher_id_users_id_fk": { | ||
"name": "resources_publisher_id_users_id_fk", | ||
"tableFrom": "resources", | ||
"tableTo": "users", | ||
"schemaTo": "public", | ||
"columnsFrom": [ | ||
"publisher_id" | ||
], | ||
"columnsTo": [ | ||
"id" | ||
], | ||
"onDelete": "no action", | ||
"onUpdate": "no action" | ||
} | ||
}, | ||
"compositePrimaryKeys": {}, | ||
"uniqueConstraints": {} | ||
}, | ||
"teams": { | ||
"name": "teams", | ||
"schema": "", | ||
"columns": { | ||
"id": { | ||
"name": "id", | ||
"type": "serial", | ||
"primaryKey": true, | ||
"notNull": true | ||
}, | ||
"provider_type": { | ||
"name": "provider_type", | ||
"type": "resources_provider", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"provider_id": { | ||
"name": "provider_id", | ||
"type": "varchar(256)", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"name": { | ||
"name": "name", | ||
"type": "varchar(256)", | ||
"primaryKey": false, | ||
"notNull": true | ||
} | ||
}, | ||
"indexes": {}, | ||
"foreignKeys": {}, | ||
"compositePrimaryKeys": {}, | ||
"uniqueConstraints": {} | ||
}, | ||
"users": { | ||
"name": "users", | ||
"schema": "", | ||
"columns": { | ||
"id": { | ||
"name": "id", | ||
"type": "serial", | ||
"primaryKey": true, | ||
"notNull": true | ||
}, | ||
"provider_type": { | ||
"name": "provider_type", | ||
"type": "resources_provider", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"provider_id": { | ||
"name": "provider_id", | ||
"type": "varchar(256)", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"name": { | ||
"name": "name", | ||
"type": "varchar(256)", | ||
"primaryKey": false, | ||
"notNull": true | ||
} | ||
}, | ||
"indexes": {}, | ||
"foreignKeys": {}, | ||
"compositePrimaryKeys": {}, | ||
"uniqueConstraints": {} | ||
} | ||
}, | ||
"enums": { | ||
"resources_provider": { | ||
"name": "resources_provider", | ||
"values": { | ||
"dmhy": "dmhy", | ||
"moe": "moe" | ||
} | ||
} | ||
}, | ||
"schemas": {}, | ||
"_meta": { | ||
"columns": {}, | ||
"schemas": {}, | ||
"tables": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"version": "5", | ||
"dialect": "pg", | ||
"entries": [ | ||
{ | ||
"idx": 0, | ||
"version": "5", | ||
"when": 1704965651813, | ||
"tag": "0000_groovy_the_watchers", | ||
"breakpoints": true | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export const hello = 1; | ||
export * from './schema'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { teams } from './team'; | ||
import { users } from './user'; | ||
import { resources } from './resource'; | ||
|
||
export type User = typeof users.$inferSelect; | ||
|
||
export type NewUser = typeof users.$inferInsert; | ||
|
||
export type Team = typeof teams.$inferSelect; | ||
|
||
export type NewTeam = typeof teams.$inferInsert; | ||
|
||
export type Resource = typeof resources.$inferSelect; | ||
|
||
export type NewResource = typeof resources.$inferInsert; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { pgEnum } from 'drizzle-orm/pg-core'; | ||
|
||
export const providerEnum = pgEnum('resources_provider', ['dmhy', 'moe']); |
Oops, something went wrong.