Skip to content

Commit

Permalink
chore: centralising database management
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasgriffintn committed Dec 18, 2024
1 parent e302b29 commit 110e534
Show file tree
Hide file tree
Showing 12 changed files with 1,390 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/database/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.wrangler
node_modules
3 changes: 3 additions & 0 deletions apps/database/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Website Database

This is a simple app for managing my database, mostly it's a centralised place where I can keep the schema.
5 changes: 5 additions & 0 deletions apps/database/drizzle.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dialect": "sqlite",
"out": "migrations",
"schema": "src/schema.ts"
}
43 changes: 43 additions & 0 deletions apps/database/migrations/0000_chubby_nicolaos.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
CREATE TABLE `document` (
`id` text PRIMARY KEY NOT NULL,
`metadata` text,
`title` text,
`content` text,
`type` text,
`created_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
`updated_at` text DEFAULT (CURRENT_TIMESTAMP)
);
--> statement-breakpoint
CREATE TABLE `oauth_account` (
`provider_id` text,
`provider_user_id` text,
`user_id` integer NOT NULL,
PRIMARY KEY(`provider_id`, `provider_user_id`),
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `session` (
`id` text PRIMARY KEY NOT NULL,
`user_id` integer NOT NULL,
`expires_at` text NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `user` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`name` text,
`avatar_url` text,
`email` text NOT NULL,
`github_username` text,
`company` text,
`site` text,
`location` text,
`bio` text,
`twitter_username` text,
`created_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
`updated_at` text DEFAULT (CURRENT_TIMESTAMP),
`setup_at` text,
`terms_accepted_at` text
);
--> statement-breakpoint
CREATE UNIQUE INDEX `user_email_unique` ON `user` (`email`);
295 changes: 295 additions & 0 deletions apps/database/migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
{
"version": "6",
"dialect": "sqlite",
"id": "9ebf61f8-9178-40ee-9ccc-5443c9361486",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"document": {
"name": "document",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"metadata": {
"name": "metadata",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"title": {
"name": "title",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"content": {
"name": "content",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"type": {
"name": "type",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(CURRENT_TIMESTAMP)"
},
"updated_at": {
"name": "updated_at",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": "(CURRENT_TIMESTAMP)"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"oauth_account": {
"name": "oauth_account",
"columns": {
"provider_id": {
"name": "provider_id",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"provider_user_id": {
"name": "provider_user_id",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"user_id": {
"name": "user_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"oauth_account_user_id_user_id_fk": {
"name": "oauth_account_user_id_user_id_fk",
"tableFrom": "oauth_account",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"oauth_account_provider_id_provider_user_id_pk": {
"columns": [
"provider_id",
"provider_user_id"
],
"name": "oauth_account_provider_id_provider_user_id_pk"
}
},
"uniqueConstraints": {},
"checkConstraints": {}
},
"session": {
"name": "session",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"user_id": {
"name": "user_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"expires_at": {
"name": "expires_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"session_user_id_user_id_fk": {
"name": "session_user_id_user_id_fk",
"tableFrom": "session",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"user": {
"name": "user",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"avatar_url": {
"name": "avatar_url",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"github_username": {
"name": "github_username",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"company": {
"name": "company",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"site": {
"name": "site",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"location": {
"name": "location",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"bio": {
"name": "bio",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"twitter_username": {
"name": "twitter_username",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(CURRENT_TIMESTAMP)"
},
"updated_at": {
"name": "updated_at",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": "(CURRENT_TIMESTAMP)"
},
"setup_at": {
"name": "setup_at",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"terms_accepted_at": {
"name": "terms_accepted_at",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {
"user_email_unique": {
"name": "user_email_unique",
"columns": [
"email"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
}
},
"views": {},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"indexes": {}
}
}
13 changes: 13 additions & 0 deletions apps/database/migrations/meta/_journal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "7",
"dialect": "sqlite",
"entries": [
{
"idx": 0,
"version": "6",
"when": 1734557335370,
"tag": "0000_chubby_nicolaos",
"breakpoints": true
}
]
}
Loading

0 comments on commit 110e534

Please sign in to comment.