Skip to content

Commit

Permalink
Merge pull request #16 from RuiOkazaki/chore/#14-create-oauth-app
Browse files Browse the repository at this point in the history
drizzle, d1, OAuthを動作させるために簡易的なアプリケーションを作成
  • Loading branch information
RuiOkazaki authored Aug 24, 2024
2 parents 0e689d9 + af0914c commit 4635366
Show file tree
Hide file tree
Showing 25 changed files with 499 additions and 164 deletions.
4 changes: 4 additions & 0 deletions .dev.vars.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
AUTH_SECRET = ""
GOOGLE_CALLBACK_BASE_URL = "http://localhost:5173"
GOOGLE_CLIENT_ID = ""
GOOGLE_CLIENT_SECRET = ""
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ node_modules
/.cache
/build
.env
.dev.vars

.wrangler
.dev.vars
5 changes: 0 additions & 5 deletions app/db/migrations/0000_fast_the_twelve.sql

This file was deleted.

47 changes: 0 additions & 47 deletions app/db/migrations/meta/0000_snapshot.json

This file was deleted.

7 changes: 0 additions & 7 deletions app/db/schema.server.ts

This file was deleted.

2 changes: 2 additions & 0 deletions app/libs/drizzle/clear.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP TABLE IF EXISTS posts;
DROP TABLE IF EXISTS users;
6 changes: 6 additions & 0 deletions app/libs/drizzle/client.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { drizzle } from "drizzle-orm/d1";

export const getDBClient = (d1: D1Database) => {
const db = drizzle(d1, { logger: import.meta.env.DEV });
return db;
};
18 changes: 18 additions & 0 deletions app/libs/drizzle/migrations/0000_sharp_piledriver.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CREATE TABLE `posts` (
`id` integer PRIMARY KEY NOT NULL,
`body` text,
`user_id` integer,
`created_at` text DEFAULT (current_timestamp) NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `users` (
`id` integer PRIMARY KEY NOT NULL,
`provider` text NOT NULL,
`provider_id` text NOT NULL,
`name` text NOT NULL,
`icon` text,
`created_at` text DEFAULT (current_timestamp) NOT NULL
);
--> statement-breakpoint
CREATE UNIQUE INDEX `users_provider_id_unique` ON `users` (`provider_id`);
129 changes: 129 additions & 0 deletions app/libs/drizzle/migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{
"version": "6",
"dialect": "sqlite",
"id": "a0c45071-1d9d-4fff-b96d-52932ed1a195",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"posts": {
"name": "posts",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"body": {
"name": "body",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"user_id": {
"name": "user_id",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(current_timestamp)"
}
},
"indexes": {},
"foreignKeys": {
"posts_user_id_users_id_fk": {
"name": "posts_user_id_users_id_fk",
"tableFrom": "posts",
"tableTo": "users",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"users": {
"name": "users",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"provider": {
"name": "provider",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"provider_id": {
"name": "provider_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"icon": {
"name": "icon",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(current_timestamp)"
}
},
"indexes": {
"users_provider_id_unique": {
"name": "users_provider_id_unique",
"columns": [
"provider_id"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"indexes": {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{
"idx": 0,
"version": "6",
"when": 1724486082546,
"tag": "0000_fast_the_twelve",
"when": 1724496526361,
"tag": "0000_sharp_piledriver",
"breakpoints": true
}
]
Expand Down
22 changes: 22 additions & 0 deletions app/libs/drizzle/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { sql } from "drizzle-orm";
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";

export const users = sqliteTable("users", {
id: integer("id").primaryKey(),
provider: text("provider").notNull(),
providerId: text("provider_id").notNull().unique(),
name: text("name").notNull(),
icon: text("icon"),
createdAt: text("created_at")
.notNull()
.default(sql`(current_timestamp)`),
});

export const posts = sqliteTable("posts", {
id: integer("id").primaryKey(),
body: text("body"),
userId: integer("user_id").references(() => users.id),
createdAt: text("created_at")
.notNull()
.default(sql`(current_timestamp)`),
});
2 changes: 1 addition & 1 deletion app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "./tailwind.css";

export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<html lang="ja">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
Expand Down
Loading

0 comments on commit 4635366

Please sign in to comment.