Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make Shelve NuxtHub compatible #325

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,5 @@ dist

*/dist/
*/.output/

.data
5 changes: 1 addition & 4 deletions apps/shelve/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { defineConfig } from 'drizzle-kit'

export default defineConfig({
dialect: 'postgresql',
dialect: 'sqlite',
schema: './server/database/schema.ts',
out: './server/database/migrations',
dbCredentials: {
url: process.env.DATABASE_URL!,
},
})
21 changes: 19 additions & 2 deletions apps/shelve/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default defineNuxtConfig({
ssr: false,

nitro: {
preset: process.env.NITRO_PRESET || 'bun',
storage: {
cache: {
driver: 'redis',
Expand All @@ -45,14 +44,32 @@ export default defineNuxtConfig({
encryptionKey: '',
adminEmails: '',
},
oauth: {
github: {
clientId: '',
clientSecret: '',
},
google: {
clientId: '',
clientSecret: '',
}
},
},

hub: {
database: true,
kv: true,
blob: true,
cache: true,
},

modules: [
'@nuxt/image',
'@nuxt/ui',
'@vueuse/nuxt',
'nuxt-build-cache',
'nuxt-auth-utils'
'nuxt-auth-utils',
'@nuxthub/core'
],

css: ['~/assets/style/main.css'],
Expand Down
23 changes: 13 additions & 10 deletions apps/shelve/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,29 @@
"typecheck": "tsc --noEmit",
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate",
"db:push": "drizzle-kit push"
"db:push": "drizzle-kit push",
"deploy": "bunx nuxthub deploy"
},
"dependencies": {
"@vueuse/core": "^11.2.0",
"@vueuse/nuxt": "^11.2.0",
"drizzle-kit": "^0.28.1",
"h3-zod": "^0.5.3",
"nuxt": "^3.14.1592",
"nuxt-auth-utils": "^0.5.5",
"nuxt-build-cache": "^0.1.1",
"resend": "^4.0.1",
"@iconify-json/heroicons": "^1.2.1",
"@iconify-json/lucide": "^1.2.15",
"@iconify-json/simple-icons": "^1.2.12",
"@nuxt/devtools": "^1.6.0",
"@nuxt/image": "^1.8.1",
"@nuxt/ui": "3.0.0-alpha.9",
"@nuxthub/core": "^0.8.7",
"@shelve/crypto": "*",
"@shelve/utils": "*",
"@vueuse/core": "^11.2.0",
"@vueuse/nuxt": "^11.2.0",
"drizzle-kit": "^0.28.1",
"drizzle-orm": "^0.36.3",
"h3-zod": "^0.5.3",
"nuxt": "^3.14.1592",
"nuxt-auth-utils": "^0.5.5",
"nuxt-build-cache": "^0.1.1",
"pg": "^8.13.1",
"resend": "^4.0.1",
"vue": "^3.5.13",
"vue-router": "^4.4.5",
"vue-sonner": "^1.2.5",
Expand All @@ -44,6 +46,7 @@
"devDependencies": {
"@shelve/types": "*",
"@types/pg": "^8.11.10",
"typescript": "^5.6.3"
"typescript": "^5.6.3",
"wrangler": "^3.89.0"
}
}
2 changes: 1 addition & 1 deletion apps/shelve/server/api/admin/users/[id].put.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default eventHandler(async (event) => {
role: z.nativeEnum(Role),
})
if (user.id === id) throw createError({ statusCode: 400, statusMessage: 'you can\'t update your own role' })
await db.update(tables.users)
await useDrizzle().update(tables.users)
.set({
role
})
Expand Down
2 changes: 1 addition & 1 deletion apps/shelve/server/api/admin/users/index.get.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default eventHandler(async () => {
return await db.query.users.findMany()
return await useDrizzle().query.users.findMany()
})
2 changes: 1 addition & 1 deletion apps/shelve/server/api/project/name/[name].get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default eventHandler(async (event) => {

if (!teamId) teamId = await new TeamService().getPrivateUserTeamId(user.id)

const project = await db.query.projects.findFirst({
const project = await useDrizzle().query.projects.findFirst({
where: and(ilike(tables.projects.name, name), eq(tables.projects.teamId, teamId)),
})

Expand Down
7 changes: 4 additions & 3 deletions apps/shelve/server/database/column.helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { timestamp } from 'drizzle-orm/pg-core'
import { text } from 'drizzle-orm/sqlite-core'
import { sql } from 'drizzle-orm'

export const timestamps = {
updatedAt: timestamp().defaultNow().notNull(),
createdAt: timestamp().defaultNow().notNull(),
createdAt: text().notNull().default(sql`(CURRENT_TIMESTAMP)`),
updatedAt: text().notNull().default(sql`(CURRENT_TIMESTAMP)`).$onUpdateFn(() => sql`(CURRENT_TIMESTAMP)`),
}
102 changes: 0 additions & 102 deletions apps/shelve/server/database/migrations/0000_bumpy_rockslide.sql

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
CREATE TABLE `members` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`userId` integer NOT NULL,
`teamId` integer NOT NULL,
`role` text DEFAULT 'member' NOT NULL,
`createdAt` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
`updatedAt` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`teamId`) REFERENCES `teams`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `projects` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`name` text NOT NULL,
`teamId` integer NOT NULL,
`description` text,
`repository` text,
`projectManager` text,
`homepage` text,
`variablePrefix` text,
`logo` text,
`createdAt` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
`updatedAt` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
FOREIGN KEY (`teamId`) REFERENCES `teams`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `teams` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`name` text NOT NULL,
`logo` text DEFAULT 'https://github.com/HugoRCD/shelve/blob/main/assets/default.png?raw=true' NOT NULL,
`private` integer DEFAULT true NOT NULL,
`privateOf` integer,
`createdAt` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
`updatedAt` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
FOREIGN KEY (`privateOf`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `tokens` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`token` text NOT NULL,
`name` text NOT NULL,
`userId` integer NOT NULL,
`createdAt` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
`updatedAt` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `users` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`username` text NOT NULL,
`email` text NOT NULL,
`avatar` text DEFAULT 'https://i.imgur.com/6VBx3io.png' NOT NULL,
`role` text DEFAULT 'user' NOT NULL,
`authType` text NOT NULL,
`createdAt` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
`updatedAt` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL
);
--> statement-breakpoint
CREATE TABLE `variables` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`projectId` integer NOT NULL,
`key` text NOT NULL,
`value` text NOT NULL,
`environment` text NOT NULL,
`createdAt` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
`updatedAt` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
FOREIGN KEY (`projectId`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade
);
Loading
Loading