Skip to content

Commit

Permalink
Merge pull request #1 from tbh-app/feat/drizzle
Browse files Browse the repository at this point in the history
feat: move to lucia auth and drizzle orm
  • Loading branch information
SrIzan10 authored Aug 21, 2024
2 parents 91be5c1 + 723671b commit c8de016
Show file tree
Hide file tree
Showing 57 changed files with 1,780 additions and 1,526 deletions.
19 changes: 19 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Dockerfile
.dockerignore
.git
.gitignore
.gitattributes
README.md
.npmrc
.prettierrc
.eslintrc.cjs
.graphqlrc
.editorconfig
.svelte-kit
.vscode
node_modules
build
package
**/.env

db/database.db
47 changes: 47 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Publish Docker image

on:
push:
branches:
- main

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: srizan10/tbh
tags: latest

- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Emit a webhook to the server
env:
AUTH_HEADER: ${{ secrets.WHSERVER_TOKEN }}
run: |
curl -X POST \
-H "Authorization: $AUTH_HEADER" \
https://webhooks.srizan.dev/hooks/tbh
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ node_modules
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
/.wrangler
/.wrangler

db/database.db
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:lts-alpine AS builder
WORKDIR /app
COPY package.json .
COPY yarn.lock .
RUN yarn install
COPY . .
RUN yarn build
RUN yarn install --production --ignore-scripts --prefer-offline

FROM node:lts-alpine
WORKDIR /app
COPY --from=builder /app/build build/
COPY --from=builder /app/public public/
COPY --from=builder /app/db db/
COPY --from=builder /app/node_modules node_modules/
COPY package.json .
EXPOSE 3000
ENV NODE_ENV=production
CMD ["node", "build"]
Empty file added db/.gitkeep
Empty file.
15 changes: 15 additions & 0 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'dotenv/config';
import { defineConfig } from 'drizzle-kit';

export default defineConfig({
dialect: 'sqlite',
out: './src/drizzle',
schema: './src/lib/server/db/schema.ts',
dbCredentials: {
url: 'db/database.db'
},
// Print all statements
verbose: true,
// Always ask for confirmation
strict: true,
});
42 changes: 18 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,42 @@
"name": "tbh",
"version": "0.0.1-alpha",
"private": true,
"packageManager": "[email protected]",
"scripts": {
"dev": "vite dev",
"dev:pages": "wrangler pages dev .svelte-kit/cloudflare",
"build": "yarn db:generateprod && vite build",
"dev": "docker compose -f dev/compose.yml up -d && vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"db:generate": "prisma generate",
"db:generateprod": "prisma generate --no-engine",
"tail": "wrangler pages deployment tail --project-name=tbh"
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/adapter-cloudflare": "^4.2.0",
"@sveltejs/adapter-node": "^5.2.1",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@types/better-sqlite3": "^7.6.11",
"@types/node": "^22.1.0",
"@types/ws": "^8.5.10",
"autoprefixer": "^10.4.17",
"daisyui": "^4.6.1",
"dotenv": "^16.4.5",
"drizzle-kit": "^0.23.2",
"postcss": "^8.4.34",
"prisma": "^5.11.0",
"svelte": "^4.2.7",
"svelte-check": "^3.6.0",
"tailwindcss": "^3.4.1",
"tslib": "^2.4.1",
"typescript": "^5.3.3",
"vite": "^5.0.3",
"wrangler": "^3.41.0"
"vite": "^5.0.3"
},
"type": "module",
"dependencies": {
"@clerk/themes": "^1.7.10",
"@neondatabase/serverless": "^0.9.0",
"@prisma/adapter-neon": "^5.11.0",
"@prisma/client": "^5.11.0",
"@prisma/extension-accelerate": "^1.0.0",
"@types/node": "^20.11.17",
"clerk-sveltekit": "^0.4.1",
"isomorphic-ws": "^5.0.0",
"ts-node": "^10.9.2",
"ws": "^8.16.0",
"zod": "^3.22.4"
}
"@lucia-auth/adapter-drizzle": "^1.0.7",
"better-sqlite3": "^11.1.2",
"drizzle-orm": "^0.32.2",
"lucia": "^3.2.0",
"lucide-svelte": "^0.381.0",
"svelte-sonner": "^0.3.27",
"zod": "^3.23.8"
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
10 changes: 0 additions & 10 deletions prisma/migrations/20240330233911_init/migration.sql

This file was deleted.

3 changes: 0 additions & 3 deletions prisma/migrations/migration_lock.toml

This file was deleted.

22 changes: 0 additions & 22 deletions prisma/schema.prisma

This file was deleted.

5 changes: 4 additions & 1 deletion src/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
declare global {
namespace App {
// interface Error {}
// interface Locals {}
interface Locals {
user: import("lucia").User | null;
session: import("lucia").Session | null;
}
// interface PageData {}
// interface PageState {}
// interface Platform {}
Expand Down
11 changes: 10 additions & 1 deletion src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script async src="https://analytics.srizan.dev/ua.js" data-website-id="ab9f3347-677f-4cdd-bc10-f68bd0c0fa6e"></script>
%sveltekit.head%

<link rel="apple-touch-icon" sizes="180x180" href="%sveltekit.assets%/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="%sveltekit.assets%/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="%sveltekit.assets%/favicon-16x16.png">
<link rel="manifest" href="%sveltekit.assets%/site.webmanifest">
<link rel="mask-icon" href="%sveltekit.assets%/safari-pinned-tab.svg" color="#5bbad5">
<meta name="apple-mobile-web-app-title" content="TBH">
<meta name="application-name" content="TBH">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
Expand Down
23 changes: 23 additions & 0 deletions src/drizzle/0000_curvy_skreet.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CREATE TABLE `question` (
`id` text PRIMARY KEY NOT NULL,
`for_username` text NOT NULL,
`text` text NOT NULL,
`created_at` text DEFAULT (CURRENT_TIMESTAMP),
FOREIGN KEY (`for_username`) REFERENCES `user`(`username`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `session` (
`id` text PRIMARY KEY NOT NULL,
`user_id` text NOT NULL,
`expires_at` integer NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `user` (
`id` text PRIMARY KEY NOT NULL,
`username` text NOT NULL,
`hashed_password` text NOT NULL,
`image_url` text DEFAULT '/tbh.webp'
);
--> statement-breakpoint
CREATE UNIQUE INDEX `user_username_unique` ON `user` (`username`);
Loading

0 comments on commit c8de016

Please sign in to comment.