Skip to content

Commit

Permalink
feat: add welcome email, alter db schema
Browse files Browse the repository at this point in the history
  • Loading branch information
enfipy committed May 26, 2024
1 parent def1064 commit 68a3ef9
Show file tree
Hide file tree
Showing 25 changed files with 560 additions and 767 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ CF_SECRET_ACCESS_KEY=
FACEBOOK_APP_ID=
FACEBOOK_APP_SECRET=

# Used to create JWT tokens
# Used to create JWT/OTP tokens
JWT_SECRET=somesecret
OTP_SECRET=somesecret

# Used to send emails
RESEND_API_KEY=
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ concurrency:

on:
workflow_dispatch:
# push:
# branches: ["main"]
# TODO: Pattern matched against refs/tags
# tags: ["*"]
push:
branches: ["main"]

jobs:
deploy-staging:
Expand Down
37 changes: 4 additions & 33 deletions apps/api/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,4 @@
import type { Config } from "drizzle-kit"
import * as path from "node:path"
import * as fs from "node:fs"

const findByExt = (base: string, ext: string, files?: string[], result?: string[]) => {
let res = result ? result : ([] as string[])
const f = files || fs.readdirSync(base)
f.forEach((file: string) => {
const newbase = path.join(base, file)
if (fs.statSync(newbase).isDirectory()) {
res = findByExt(newbase, ext, fs.readdirSync(newbase), res)
} else {
if (file.slice(-1 * ext.length) === ext) {
res.push(newbase)
}
}
})
return res
}

const getLocalSqliteUrl = () => {
let sqliteFiles: string[] = []
try {
sqliteFiles = findByExt("./.wrangler", ".sqlite")
} catch (e) {
console.error("failed to find, got error", e)
}
if (sqliteFiles.length === 0) {
console.warn("No sqlite files found in .wrangler folder")
}
return sqliteFiles[0] || ""
}

/**
* This is the config for __drizzle-kit__.
Expand All @@ -43,8 +12,10 @@ const getLocalSqliteUrl = () => {
export default {
schema: "./src/db/schema.ts",
out: "./migrations",
driver: "better-sqlite",
dialect: "sqlite",
driver: "d1",
dbCredentials: {
url: getLocalSqliteUrl(),
wranglerConfigPath: "./wrangler.toml",
dbName: "dev-db",
},
} satisfies Config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ CREATE TABLE `authSessions` (
`signedInWith` integer NOT NULL,
`device` text NOT NULL,
`ipLocation` text NOT NULL,
`emailAuthOTP` text,
`isActive` integer NOT NULL,
`userId` text NOT NULL,
FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
Expand All @@ -19,25 +18,50 @@ CREATE TABLE `categories` (
`icon` text NOT NULL
);
--> statement-breakpoint
CREATE TABLE `otpVerifications` (
`id` text PRIMARY KEY NOT NULL,
`createdAt` integer NOT NULL,
`secret` text NOT NULL,
`type` integer NOT NULL,
`userId` text NOT NULL,
FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `users` (
`id` text PRIMARY KEY NOT NULL,
`updatedAt` integer,
`createdAt` integer NOT NULL,
`onboardingStatus` integer DEFAULT 0 NOT NULL,
`signedUpWith` integer NOT NULL,
`email` text,
`emailVerificationOTP` text,
`emailVerified` integer DEFAULT false NOT NULL,
`username` text,
`username` text NOT NULL,
`previousUsername` text,
`usernameUpdatedAt` integer,
`firstName` text,
`lastName` text,
`appleId` text,
`googleId` text,
`facebookId` text,
`avatarIndex` integer DEFAULT 0 NOT NULL,
`avatarIndex` integer,
`storage` integer DEFAULT 0 NOT NULL
);
--> statement-breakpoint
CREATE TABLE `videoComments` (
`id` text PRIMARY KEY NOT NULL,
`updatedAt` integer,
`createdAt` integer NOT NULL,
`value` text NOT NULL,
`commentType` integer DEFAULT 0 NOT NULL,
`status` integer DEFAULT 0 NOT NULL,
`videoId` text NOT NULL,
`replyToCommentId` text,
`userId` text NOT NULL,
FOREIGN KEY (`videoId`) REFERENCES `videos`(`id`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`replyToCommentId`) REFERENCES `videoComments`(`id`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `videos` (
`id` text PRIMARY KEY NOT NULL,
`updatedAt` integer,
Expand Down
22 changes: 0 additions & 22 deletions apps/api/migrations/0001_lovely_kat_farrell.sql

This file was deleted.

193 changes: 174 additions & 19 deletions apps/api/migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "5",
"version": "6",
"dialect": "sqlite",
"id": "a518a3d1-9ce3-45d2-af57-385ece4d3558",
"id": "54c125d3-96d5-46f9-ac8e-c92cfea571e6",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"authSessions": {
Expand Down Expand Up @@ -42,13 +42,6 @@
"notNull": true,
"autoincrement": false
},
"emailAuthOTP": {
"name": "emailAuthOTP",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"isActive": {
"name": "isActive",
"type": "integer",
Expand Down Expand Up @@ -130,6 +123,60 @@
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"otpVerifications": {
"name": "otpVerifications",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"createdAt": {
"name": "createdAt",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"secret": {
"name": "secret",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"type": {
"name": "type",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"userId": {
"name": "userId",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"otpVerifications_userId_users_id_fk": {
"name": "otpVerifications_userId_users_id_fk",
"tableFrom": "otpVerifications",
"tableTo": "users",
"columnsFrom": ["userId"],
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"users": {
"name": "users",
"columns": {
Expand Down Expand Up @@ -176,13 +223,6 @@
"notNull": false,
"autoincrement": false
},
"emailVerificationOTP": {
"name": "emailVerificationOTP",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"emailVerified": {
"name": "emailVerified",
"type": "integer",
Expand All @@ -195,6 +235,20 @@
"name": "username",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"previousUsername": {
"name": "previousUsername",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"usernameUpdatedAt": {
"name": "usernameUpdatedAt",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
Expand Down Expand Up @@ -237,9 +291,8 @@
"name": "avatarIndex",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0
"notNull": false,
"autoincrement": false
},
"storage": {
"name": "storage",
Expand Down Expand Up @@ -281,6 +334,108 @@
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"videoComments": {
"name": "videoComments",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"updatedAt": {
"name": "updatedAt",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"createdAt": {
"name": "createdAt",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"value": {
"name": "value",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"commentType": {
"name": "commentType",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0
},
"status": {
"name": "status",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0
},
"videoId": {
"name": "videoId",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"replyToCommentId": {
"name": "replyToCommentId",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"userId": {
"name": "userId",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"videoComments_videoId_videos_id_fk": {
"name": "videoComments_videoId_videos_id_fk",
"tableFrom": "videoComments",
"tableTo": "videos",
"columnsFrom": ["videoId"],
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
},
"videoComments_replyToCommentId_videoComments_id_fk": {
"name": "videoComments_replyToCommentId_videoComments_id_fk",
"tableFrom": "videoComments",
"tableTo": "videoComments",
"columnsFrom": ["replyToCommentId"],
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
},
"videoComments_userId_users_id_fk": {
"name": "videoComments_userId_users_id_fk",
"tableFrom": "videoComments",
"tableTo": "users",
"columnsFrom": ["userId"],
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"videos": {
"name": "videos",
"columns": {
Expand Down
Loading

0 comments on commit 68a3ef9

Please sign in to comment.