Working on arthome

This commit is contained in:
2024-08-30 14:22:29 +02:00
parent a1e31a89a7
commit 396e8a6850
51 changed files with 2019 additions and 2290 deletions

View File

@@ -0,0 +1,18 @@
export default defineEventHandler(async (event) => {
try {
const user = await getUserSession(event)
const { id } = await getRouterParams(event)
await useDrizzle()
.delete(tables.categories)
.where(
and(
eq(tables.categories.id, id),
eq(tables.categories.userId, user.id),
),
)
return { statusCode: 200 }
}
catch (err) {
return { err }
}
})

View File

@@ -0,0 +1,28 @@
import { useValidatedBody } from 'h3-zod'
import { UpdateCategorySchema } from '~~/types/types'
export default defineEventHandler(async (event) => {
try {
const user = await getUserSession(event)
const { id } = await getRouterParams(event)
const body = await useValidatedBody(event, UpdateCategorySchema)
await useDrizzle()
.update(tables.categories)
.set({
name: body.name,
icon: body.icon,
color: body.color,
nameVisible: body.nameVisible,
})
.where(
and(
eq(tables.categories.id, id),
eq(tables.categories.userId, user.id),
),
)
return { statusCode: 200 }
}
catch (err) {
return { err }
}
})

View File

@@ -1,7 +1,10 @@
export default defineEventHandler(async (event) => {
const user = await getUserSession(event)
console.log('session', user)
return useDrizzle().query.categories.findMany({
where: eq(tables.users.id, user.id),
})
const user = await requireUserSession(event)
return useDrizzle()
.select()
.from(tables.categories)
.where(
eq(tables.categories.userId, user.user.id),
)
.orderBy(tables.categories.id, 'desc')
})

View File

@@ -0,0 +1,20 @@
import { useValidatedBody } from 'h3-zod'
import { CreateCategorySchema } from '~~/types/types'
export default defineEventHandler(async (event) => {
try {
const user = await getUserSession(event)
const body = await useValidatedBody(event, CreateCategorySchema)
await useDrizzle().insert(tables.categories).values({
name: body.name,
icon: body.icon,
color: body.color,
nameVisible: body.nameVisible,
userId: user.id,
})
return { statusCode: 200 }
}
catch (err) {
return { err }
}
})

View File

@@ -0,0 +1,16 @@
export default defineEventHandler(async (event) => {
try {
const { id } = await getRouterParams(event)
await useDrizzle()
.delete(tables.tabs)
.where(
and(
eq(tables.tabs.id, id),
),
)
return { statusCode: 200 }
}
catch (err) {
return { err }
}
})

View File

@@ -0,0 +1,29 @@
import { useValidatedBody } from 'h3-zod'
import { UpdateTabSchema } from '~~/types/types'
export default defineEventHandler(async (event) => {
try {
const { id } = await getRouterParams(event)
console.log(await readBody(event))
const body = await useValidatedBody(event, UpdateTabSchema)
await useDrizzle()
.update(tables.tabs)
.set({
name: body.name,
icon: body.icon,
color: body.color,
nameVisible: body.nameVisible,
link: body.link,
})
.where(
and(
eq(tables.tabs.id, id),
eq(tables.tabs.categoryId, body.categoryId),
),
)
return { statusCode: 200 }
}
catch (err) {
return { err }
}
})

View File

@@ -0,0 +1,6 @@
export default defineEventHandler(async () => {
return useDrizzle()
.select()
.from(tables.tabs)
.orderBy(tables.tabs.id, 'desc')
})

View File

@@ -0,0 +1,20 @@
import { useValidatedBody } from 'h3-zod'
import { CreateTabSchema } from '~~/types/types'
export default defineEventHandler(async (event) => {
try {
const body = await useValidatedBody(event, CreateTabSchema)
await useDrizzle().insert(tables.tabs).values({
name: body.name,
icon: body.icon,
color: body.color,
nameVisible: body.nameVisible,
categoryId: body.categoryId,
link: body.link,
})
return { statusCode: 200 }
}
catch (err) {
return { err }
}
})

View File

@@ -6,17 +6,10 @@ END $$;
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "categories" (
"id" serial PRIMARY KEY NOT NULL,
"name" text DEFAULT '' NOT NULL,
"name_visible" boolean DEFAULT true NOT NULL,
"icon" text DEFAULT 'i-ph:circle-wavy-question-duotone' NOT NULL,
"color" text DEFAULT 'gray' NOT NULL,
"page_id" integer NOT NULL,
"created_at" timestamp (3) DEFAULT now(),
"updated_at" timestamp (3)
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "pages" (
"id" serial PRIMARY KEY NOT NULL,
"name" text DEFAULT '',
"name_visible" boolean DEFAULT true,
"icon" text DEFAULT 'i-ph:circle-wavy-question-duotone',
"color" text DEFAULT 'gray',
"user_id" integer NOT NULL,
"created_at" timestamp (3) DEFAULT now(),
"updated_at" timestamp (3)
@@ -24,10 +17,10 @@ CREATE TABLE IF NOT EXISTS "pages" (
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "tabs" (
"id" serial PRIMARY KEY NOT NULL,
"name" text DEFAULT '' NOT NULL,
"name_visible" boolean DEFAULT true NOT NULL,
"icon" text DEFAULT 'i-ph:circle-wavy-question-duotone' NOT NULL,
"color" text DEFAULT 'gray' NOT NULL,
"name" text DEFAULT '',
"name_visible" boolean DEFAULT true,
"icon" text DEFAULT 'i-ph:circle-wavy-question-duotone',
"color" text DEFAULT 'gray',
"category_id" integer NOT NULL,
"created_at" timestamp (3) DEFAULT now(),
"updated_at" timestamp (3)
@@ -43,10 +36,11 @@ CREATE TABLE IF NOT EXISTS "users" (
"google_id" text,
"google_token" text,
"description" text DEFAULT '',
"private" boolean DEFAULT false NOT NULL,
"timezone" text DEFAULT 'undefined' NOT NULL,
"location" text DEFAULT 'undefined' NOT NULL,
"subscription" "subscription" DEFAULT 'free' NOT NULL,
"avatar" text DEFAULT '',
"private" boolean DEFAULT false,
"language" text DEFAULT 'en-EN',
"location" text DEFAULT 'unknown',
"subscription" "subscription" DEFAULT 'free',
"created_at" timestamp (3) DEFAULT now(),
"updated_at" timestamp (3),
CONSTRAINT "users_email_unique" UNIQUE("email"),
@@ -55,13 +49,7 @@ CREATE TABLE IF NOT EXISTS "users" (
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "categories" ADD CONSTRAINT "categories_page_id_pages_id_fk" FOREIGN KEY ("page_id") REFERENCES "public"."pages"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "pages" ADD CONSTRAINT "pages_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;
ALTER TABLE "categories" ADD CONSTRAINT "categories_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;

View File

@@ -0,0 +1 @@
ALTER TABLE "tabs" ADD COLUMN "link" text DEFAULT '';

View File

@@ -1,4 +0,0 @@
ALTER TABLE "categories" ALTER COLUMN "id" SET DATA TYPE integer;--> statement-breakpoint
ALTER TABLE "pages" ALTER COLUMN "id" SET DATA TYPE integer;--> statement-breakpoint
ALTER TABLE "tabs" ALTER COLUMN "id" SET DATA TYPE integer;--> statement-breakpoint
ALTER TABLE "users" ALTER COLUMN "id" SET DATA TYPE integer;

View File

@@ -0,0 +1,2 @@
ALTER TABLE "tabs" ADD COLUMN "primary" boolean DEFAULT false;--> statement-breakpoint
ALTER TABLE "tabs" DROP COLUMN IF EXISTS "name_visible";

View File

@@ -1,13 +0,0 @@
ALTER TABLE "categories" ALTER COLUMN "name" DROP NOT NULL;--> statement-breakpoint
ALTER TABLE "categories" ALTER COLUMN "name_visible" DROP NOT NULL;--> statement-breakpoint
ALTER TABLE "categories" ALTER COLUMN "icon" DROP NOT NULL;--> statement-breakpoint
ALTER TABLE "categories" ALTER COLUMN "color" DROP NOT NULL;--> statement-breakpoint
ALTER TABLE "tabs" ALTER COLUMN "name" DROP NOT NULL;--> statement-breakpoint
ALTER TABLE "tabs" ALTER COLUMN "name_visible" DROP NOT NULL;--> statement-breakpoint
ALTER TABLE "tabs" ALTER COLUMN "icon" DROP NOT NULL;--> statement-breakpoint
ALTER TABLE "tabs" ALTER COLUMN "color" DROP NOT NULL;--> statement-breakpoint
ALTER TABLE "users" ALTER COLUMN "private" DROP NOT NULL;--> statement-breakpoint
ALTER TABLE "users" ALTER COLUMN "timezone" DROP NOT NULL;--> statement-breakpoint
ALTER TABLE "users" ALTER COLUMN "location" SET DEFAULT 'unknown';--> statement-breakpoint
ALTER TABLE "users" ALTER COLUMN "location" DROP NOT NULL;--> statement-breakpoint
ALTER TABLE "users" ALTER COLUMN "subscription" DROP NOT NULL;

View File

@@ -1 +0,0 @@
ALTER TABLE "users" ADD COLUMN "avatar" text DEFAULT '';

View File

@@ -1,2 +0,0 @@
ALTER TABLE "users" RENAME COLUMN "timezone" TO "language";--> statement-breakpoint
ALTER TABLE "users" ALTER COLUMN "language" SET DEFAULT 'english';

View File

@@ -1 +0,0 @@
ALTER TABLE "users" ALTER COLUMN "language" SET DEFAULT 'en-EN';

View File

@@ -1,5 +1,5 @@
{
"id": "a8ec7e1e-1087-4ab5-be19-459dc9b0a4e0",
"id": "c52dbfc1-beae-4a41-8725-66def9fdacea",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
@@ -18,78 +18,29 @@
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"notNull": false,
"default": "''"
},
"name_visible": {
"name": "name_visible",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"notNull": false,
"default": true
},
"icon": {
"name": "icon",
"type": "text",
"primaryKey": false,
"notNull": true,
"notNull": false,
"default": "'i-ph:circle-wavy-question-duotone'"
},
"color": {
"name": "color",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'gray'"
},
"page_id": {
"name": "page_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"categories_page_id_pages_id_fk": {
"name": "categories_page_id_pages_id_fk",
"tableFrom": "categories",
"tableTo": "pages",
"columnsFrom": [
"page_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.pages": {
"name": "pages",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
"default": "'gray'"
},
"user_id": {
"name": "user_id",
@@ -113,9 +64,9 @@
},
"indexes": {},
"foreignKeys": {
"pages_user_id_users_id_fk": {
"name": "pages_user_id_users_id_fk",
"tableFrom": "pages",
"categories_user_id_users_id_fk": {
"name": "categories_user_id_users_id_fk",
"tableFrom": "categories",
"tableTo": "users",
"columnsFrom": [
"user_id"
@@ -144,28 +95,28 @@
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"notNull": false,
"default": "''"
},
"name_visible": {
"name": "name_visible",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"notNull": false,
"default": true
},
"icon": {
"name": "icon",
"type": "text",
"primaryKey": false,
"notNull": true,
"notNull": false,
"default": "'i-ph:circle-wavy-question-duotone'"
},
"color": {
"name": "color",
"type": "text",
"primaryKey": false,
"notNull": true,
"notNull": false,
"default": "'gray'"
},
"category_id": {
@@ -266,33 +217,40 @@
"notNull": false,
"default": "''"
},
"avatar": {
"name": "avatar",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"private": {
"name": "private",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"notNull": false,
"default": false
},
"timezone": {
"name": "timezone",
"language": {
"name": "language",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'undefined'"
"notNull": false,
"default": "'en-EN'"
},
"location": {
"name": "location",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'undefined'"
"notNull": false,
"default": "'unknown'"
},
"subscription": {
"name": "subscription",
"type": "subscription",
"typeSchema": "public",
"primaryKey": false,
"notNull": true,
"notNull": false,
"default": "'free'"
},
"created_at": {
@@ -354,4 +312,4 @@
"schemas": {},
"tables": {}
}
}
}

View File

@@ -1,6 +1,6 @@
{
"id": "0550ff2a-d819-4a38-a515-915d5ef620a6",
"prevId": "a8ec7e1e-1087-4ab5-be19-459dc9b0a4e0",
"id": "1a96f2ca-db04-445d-b671-d61aaeef8882",
"prevId": "c52dbfc1-beae-4a41-8725-66def9fdacea",
"version": "7",
"dialect": "postgresql",
"tables": {
@@ -10,7 +10,7 @@
"columns": {
"id": {
"name": "id",
"type": "integer",
"type": "serial",
"primaryKey": true,
"notNull": true
},
@@ -18,78 +18,29 @@
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"notNull": false,
"default": "''"
},
"name_visible": {
"name": "name_visible",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"notNull": false,
"default": true
},
"icon": {
"name": "icon",
"type": "text",
"primaryKey": false,
"notNull": true,
"notNull": false,
"default": "'i-ph:circle-wavy-question-duotone'"
},
"color": {
"name": "color",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'gray'"
},
"page_id": {
"name": "page_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"categories_page_id_pages_id_fk": {
"name": "categories_page_id_pages_id_fk",
"tableFrom": "categories",
"tableTo": "pages",
"columnsFrom": [
"page_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.pages": {
"name": "pages",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true
"default": "'gray'"
},
"user_id": {
"name": "user_id",
@@ -113,9 +64,9 @@
},
"indexes": {},
"foreignKeys": {
"pages_user_id_users_id_fk": {
"name": "pages_user_id_users_id_fk",
"tableFrom": "pages",
"categories_user_id_users_id_fk": {
"name": "categories_user_id_users_id_fk",
"tableFrom": "categories",
"tableTo": "users",
"columnsFrom": [
"user_id"
@@ -136,7 +87,7 @@
"columns": {
"id": {
"name": "id",
"type": "integer",
"type": "serial",
"primaryKey": true,
"notNull": true
},
@@ -144,30 +95,37 @@
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"notNull": false,
"default": "''"
},
"name_visible": {
"name": "name_visible",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"notNull": false,
"default": true
},
"icon": {
"name": "icon",
"type": "text",
"primaryKey": false,
"notNull": true,
"notNull": false,
"default": "'i-ph:circle-wavy-question-duotone'"
},
"color": {
"name": "color",
"type": "text",
"primaryKey": false,
"notNull": true,
"notNull": false,
"default": "'gray'"
},
"link": {
"name": "link",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"category_id": {
"name": "category_id",
"type": "integer",
@@ -213,7 +171,7 @@
"columns": {
"id": {
"name": "id",
"type": "integer",
"type": "serial",
"primaryKey": true,
"notNull": true
},
@@ -266,33 +224,40 @@
"notNull": false,
"default": "''"
},
"avatar": {
"name": "avatar",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"private": {
"name": "private",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"notNull": false,
"default": false
},
"timezone": {
"name": "timezone",
"language": {
"name": "language",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'undefined'"
"notNull": false,
"default": "'en-EN'"
},
"location": {
"name": "location",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'undefined'"
"notNull": false,
"default": "'unknown'"
},
"subscription": {
"name": "subscription",
"type": "subscription",
"typeSchema": "public",
"primaryKey": false,
"notNull": true,
"notNull": false,
"default": "'free'"
},
"created_at": {
@@ -354,4 +319,4 @@
"schemas": {},
"tables": {}
}
}
}

View File

@@ -1,6 +1,6 @@
{
"id": "7d4e591a-f6c7-48eb-b9e8-e0e200bfea26",
"prevId": "0550ff2a-d819-4a38-a515-915d5ef620a6",
"id": "b9aba4fe-7f04-4acc-b47f-2d29d739df98",
"prevId": "1a96f2ca-db04-445d-b671-d61aaeef8882",
"version": "7",
"dialect": "postgresql",
"tables": {
@@ -10,7 +10,7 @@
"columns": {
"id": {
"name": "id",
"type": "integer",
"type": "serial",
"primaryKey": true,
"notNull": true
},
@@ -42,55 +42,6 @@
"notNull": false,
"default": "'gray'"
},
"page_id": {
"name": "page_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"categories_page_id_pages_id_fk": {
"name": "categories_page_id_pages_id_fk",
"tableFrom": "categories",
"tableTo": "pages",
"columnsFrom": [
"page_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.pages": {
"name": "pages",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "integer",
@@ -113,9 +64,9 @@
},
"indexes": {},
"foreignKeys": {
"pages_user_id_users_id_fk": {
"name": "pages_user_id_users_id_fk",
"tableFrom": "pages",
"categories_user_id_users_id_fk": {
"name": "categories_user_id_users_id_fk",
"tableFrom": "categories",
"tableTo": "users",
"columnsFrom": [
"user_id"
@@ -136,7 +87,7 @@
"columns": {
"id": {
"name": "id",
"type": "integer",
"type": "serial",
"primaryKey": true,
"notNull": true
},
@@ -147,12 +98,12 @@
"notNull": false,
"default": "''"
},
"name_visible": {
"name": "name_visible",
"primary": {
"name": "primary",
"type": "boolean",
"primaryKey": false,
"notNull": false,
"default": true
"default": false
},
"icon": {
"name": "icon",
@@ -168,6 +119,13 @@
"notNull": false,
"default": "'gray'"
},
"link": {
"name": "link",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"category_id": {
"name": "category_id",
"type": "integer",
@@ -213,7 +171,7 @@
"columns": {
"id": {
"name": "id",
"type": "integer",
"type": "serial",
"primaryKey": true,
"notNull": true
},
@@ -266,6 +224,13 @@
"notNull": false,
"default": "''"
},
"avatar": {
"name": "avatar",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"private": {
"name": "private",
"type": "boolean",
@@ -273,12 +238,12 @@
"notNull": false,
"default": false
},
"timezone": {
"name": "timezone",
"language": {
"name": "language",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'undefined'"
"default": "'en-EN'"
},
"location": {
"name": "location",

View File

@@ -1,364 +0,0 @@
{
"id": "d4ae60ba-5be1-4aa9-90d7-0690a599bf8e",
"prevId": "7d4e591a-f6c7-48eb-b9e8-e0e200bfea26",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.categories": {
"name": "categories",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"name_visible": {
"name": "name_visible",
"type": "boolean",
"primaryKey": false,
"notNull": false,
"default": true
},
"icon": {
"name": "icon",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'i-ph:circle-wavy-question-duotone'"
},
"color": {
"name": "color",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'gray'"
},
"page_id": {
"name": "page_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"categories_page_id_pages_id_fk": {
"name": "categories_page_id_pages_id_fk",
"tableFrom": "categories",
"tableTo": "pages",
"columnsFrom": [
"page_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.pages": {
"name": "pages",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"pages_user_id_users_id_fk": {
"name": "pages_user_id_users_id_fk",
"tableFrom": "pages",
"tableTo": "users",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.tabs": {
"name": "tabs",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"name_visible": {
"name": "name_visible",
"type": "boolean",
"primaryKey": false,
"notNull": false,
"default": true
},
"icon": {
"name": "icon",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'i-ph:circle-wavy-question-duotone'"
},
"color": {
"name": "color",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'gray'"
},
"category_id": {
"name": "category_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"tabs_category_id_categories_id_fk": {
"name": "tabs_category_id_categories_id_fk",
"tableFrom": "tabs",
"tableTo": "categories",
"columnsFrom": [
"category_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.users": {
"name": "users",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true
},
"username": {
"name": "username",
"type": "text",
"primaryKey": false,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true
},
"github_id": {
"name": "github_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"github_token": {
"name": "github_token",
"type": "text",
"primaryKey": false,
"notNull": false
},
"google_id": {
"name": "google_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"google_token": {
"name": "google_token",
"type": "text",
"primaryKey": false,
"notNull": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"avatar": {
"name": "avatar",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"private": {
"name": "private",
"type": "boolean",
"primaryKey": false,
"notNull": false,
"default": false
},
"timezone": {
"name": "timezone",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'undefined'"
},
"location": {
"name": "location",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'unknown'"
},
"subscription": {
"name": "subscription",
"type": "subscription",
"typeSchema": "public",
"primaryKey": false,
"notNull": false,
"default": "'free'"
},
"created_at": {
"name": "created_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"users_email_unique": {
"name": "users_email_unique",
"nullsNotDistinct": false,
"columns": [
"email"
]
},
"users_github_id_unique": {
"name": "users_github_id_unique",
"nullsNotDistinct": false,
"columns": [
"github_id"
]
},
"users_google_id_unique": {
"name": "users_google_id_unique",
"nullsNotDistinct": false,
"columns": [
"google_id"
]
}
}
}
},
"enums": {
"public.subscription": {
"name": "subscription",
"schema": "public",
"values": [
"free",
"paid"
]
}
},
"schemas": {},
"sequences": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}

View File

@@ -1,364 +0,0 @@
{
"id": "704c03b2-8d7f-47ce-a551-95289048c5f2",
"prevId": "d4ae60ba-5be1-4aa9-90d7-0690a599bf8e",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.categories": {
"name": "categories",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"name_visible": {
"name": "name_visible",
"type": "boolean",
"primaryKey": false,
"notNull": false,
"default": true
},
"icon": {
"name": "icon",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'i-ph:circle-wavy-question-duotone'"
},
"color": {
"name": "color",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'gray'"
},
"page_id": {
"name": "page_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"categories_page_id_pages_id_fk": {
"name": "categories_page_id_pages_id_fk",
"tableFrom": "categories",
"tableTo": "pages",
"columnsFrom": [
"page_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.pages": {
"name": "pages",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"pages_user_id_users_id_fk": {
"name": "pages_user_id_users_id_fk",
"tableFrom": "pages",
"tableTo": "users",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.tabs": {
"name": "tabs",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"name_visible": {
"name": "name_visible",
"type": "boolean",
"primaryKey": false,
"notNull": false,
"default": true
},
"icon": {
"name": "icon",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'i-ph:circle-wavy-question-duotone'"
},
"color": {
"name": "color",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'gray'"
},
"category_id": {
"name": "category_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"tabs_category_id_categories_id_fk": {
"name": "tabs_category_id_categories_id_fk",
"tableFrom": "tabs",
"tableTo": "categories",
"columnsFrom": [
"category_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.users": {
"name": "users",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true
},
"username": {
"name": "username",
"type": "text",
"primaryKey": false,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true
},
"github_id": {
"name": "github_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"github_token": {
"name": "github_token",
"type": "text",
"primaryKey": false,
"notNull": false
},
"google_id": {
"name": "google_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"google_token": {
"name": "google_token",
"type": "text",
"primaryKey": false,
"notNull": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"avatar": {
"name": "avatar",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"private": {
"name": "private",
"type": "boolean",
"primaryKey": false,
"notNull": false,
"default": false
},
"language": {
"name": "language",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'english'"
},
"location": {
"name": "location",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'unknown'"
},
"subscription": {
"name": "subscription",
"type": "subscription",
"typeSchema": "public",
"primaryKey": false,
"notNull": false,
"default": "'free'"
},
"created_at": {
"name": "created_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"users_email_unique": {
"name": "users_email_unique",
"nullsNotDistinct": false,
"columns": [
"email"
]
},
"users_github_id_unique": {
"name": "users_github_id_unique",
"nullsNotDistinct": false,
"columns": [
"github_id"
]
},
"users_google_id_unique": {
"name": "users_google_id_unique",
"nullsNotDistinct": false,
"columns": [
"google_id"
]
}
}
}
},
"enums": {
"public.subscription": {
"name": "subscription",
"schema": "public",
"values": [
"free",
"paid"
]
}
},
"schemas": {},
"sequences": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}

View File

@@ -1,364 +0,0 @@
{
"id": "e891a8e0-61c1-4351-90fe-caace29457a8",
"prevId": "704c03b2-8d7f-47ce-a551-95289048c5f2",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.categories": {
"name": "categories",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"name_visible": {
"name": "name_visible",
"type": "boolean",
"primaryKey": false,
"notNull": false,
"default": true
},
"icon": {
"name": "icon",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'i-ph:circle-wavy-question-duotone'"
},
"color": {
"name": "color",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'gray'"
},
"page_id": {
"name": "page_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"categories_page_id_pages_id_fk": {
"name": "categories_page_id_pages_id_fk",
"tableFrom": "categories",
"tableTo": "pages",
"columnsFrom": [
"page_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.pages": {
"name": "pages",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"pages_user_id_users_id_fk": {
"name": "pages_user_id_users_id_fk",
"tableFrom": "pages",
"tableTo": "users",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.tabs": {
"name": "tabs",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"name_visible": {
"name": "name_visible",
"type": "boolean",
"primaryKey": false,
"notNull": false,
"default": true
},
"icon": {
"name": "icon",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'i-ph:circle-wavy-question-duotone'"
},
"color": {
"name": "color",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'gray'"
},
"category_id": {
"name": "category_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"tabs_category_id_categories_id_fk": {
"name": "tabs_category_id_categories_id_fk",
"tableFrom": "tabs",
"tableTo": "categories",
"columnsFrom": [
"category_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.users": {
"name": "users",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true
},
"username": {
"name": "username",
"type": "text",
"primaryKey": false,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true
},
"github_id": {
"name": "github_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"github_token": {
"name": "github_token",
"type": "text",
"primaryKey": false,
"notNull": false
},
"google_id": {
"name": "google_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"google_token": {
"name": "google_token",
"type": "text",
"primaryKey": false,
"notNull": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"avatar": {
"name": "avatar",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"private": {
"name": "private",
"type": "boolean",
"primaryKey": false,
"notNull": false,
"default": false
},
"language": {
"name": "language",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'en-EN'"
},
"location": {
"name": "location",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'unknown'"
},
"subscription": {
"name": "subscription",
"type": "subscription",
"typeSchema": "public",
"primaryKey": false,
"notNull": false,
"default": "'free'"
},
"created_at": {
"name": "created_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"users_email_unique": {
"name": "users_email_unique",
"nullsNotDistinct": false,
"columns": [
"email"
]
},
"users_github_id_unique": {
"name": "users_github_id_unique",
"nullsNotDistinct": false,
"columns": [
"github_id"
]
},
"users_google_id_unique": {
"name": "users_google_id_unique",
"nullsNotDistinct": false,
"columns": [
"google_id"
]
}
}
}
},
"enums": {
"public.subscription": {
"name": "subscription",
"schema": "public",
"values": [
"free",
"paid"
]
}
},
"schemas": {},
"sequences": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}

View File

@@ -5,43 +5,22 @@
{
"idx": 0,
"version": "7",
"when": 1724455773734,
"tag": "0000_wild_luke_cage",
"when": 1724865045534,
"tag": "0000_giant_stranger",
"breakpoints": true
},
{
"idx": 1,
"version": "7",
"when": 1724455851539,
"tag": "0001_goofy_dormammu",
"when": 1724884620789,
"tag": "0001_fancy_tyger_tiger",
"breakpoints": true
},
{
"idx": 2,
"version": "7",
"when": 1724456130150,
"tag": "0002_slim_whistler",
"breakpoints": true
},
{
"idx": 3,
"version": "7",
"when": 1724528975297,
"tag": "0003_curious_solo",
"breakpoints": true
},
{
"idx": 4,
"version": "7",
"when": 1724531645621,
"tag": "0004_sharp_shocker",
"breakpoints": true
},
{
"idx": 5,
"version": "7",
"when": 1724532003950,
"tag": "0005_tense_the_order",
"when": 1725015619221,
"tag": "0002_cool_dexter_bennett",
"breakpoints": true
}
]

View File

@@ -23,53 +23,39 @@ export const users = pgTable('users', {
...timestamps,
})
export const pages = pgTable('pages', {
id,
userId: integer('user_id')
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
...timestamps,
})
export const categories = pgTable('categories', {
id,
name: text('name').default(''),
nameVisible: boolean('name_visible').default(true),
icon: text('icon').default('i-ph:circle-wavy-question-duotone'),
color: text('color').default('gray'),
pageId: integer('page_id')
userId: integer('user_id')
.notNull()
.references(() => pages.id, { onDelete: 'cascade' }),
.references(() => users.id, { onDelete: 'cascade' }),
...timestamps,
})
export const tabs = pgTable('tabs', {
id,
name: text('name').default(''),
nameVisible: boolean('name_visible').default(true),
primary: boolean('primary').default(false),
icon: text('icon').default('i-ph:circle-wavy-question-duotone'),
color: text('color').default('gray'),
link: text('link').default(''),
categoryId: integer('category_id')
.notNull()
.references(() => categories.id, { onDelete: 'cascade' }),
...timestamps,
})
export const usersRelations = relations(users, ({ one }) => ({
page: one(pages, {
fields: [users.id],
references: [pages.userId],
}),
}))
export const pagesRelations = relations(pages, ({ many }) => ({
export const usersRelations = relations(users, ({ many }) => ({
categories: many(categories),
}))
export const categoriesRelations = relations(categories, ({ one, many }) => ({
page: one(pages, {
fields: [categories.pageId],
references: [pages.id],
user: one(users, {
fields: [categories.userId],
references: [users.id],
}),
tabs: many(tabs),
}))

View File

@@ -1,6 +1,7 @@
export default oauthGoogleEventHandler({
config: {
emailRequired: true,
scope: ['email', 'profile'],
},
async onSuccess(event, { user: oauthUser, tokens }) {
const userSession = await getUserSession(event)
@@ -15,7 +16,7 @@ export default oauthGoogleEventHandler({
googleToken: tokens.access_token,
})
await replaceUserSession(event, {
await setUserSession(event, {
id: userSession.id,
user: userSession,
googleId: oauthUser.sub,
@@ -35,7 +36,7 @@ export default oauthGoogleEventHandler({
googleToken: tokens.access_token,
})
await replaceUserSession(event, {
await setUserSession(event, {
id: user.id,
user,
})
@@ -76,7 +77,7 @@ export default oauthGoogleEventHandler({
subscription: 'free',
})
await replaceUserSession(event, {
await setUserSession(event, {
id: createdUser.id,
user: createdUser,
})

View File

@@ -10,9 +10,3 @@ export function useDrizzle() {
const config = useRuntimeConfig()
return drizzle(postgres(config.postgres.url, { prepare: false }), { schema })
}
export type UserType = typeof schema.users.$inferSelect
export type UserInsert = typeof schema.users.$inferInsert
export type TabType = typeof schema.tabs.$inferSelect
export type CategoryType = typeof schema.categories.$inferSelect

View File

@@ -1,18 +1,11 @@
import * as pg from 'drizzle-orm/pg-core'
import { serial, timestamp } from 'drizzle-orm/pg-core'
/**
* A centralized list of standardized Drizzle ORM schema field definitions to prevent duplication errors
*/
export const createdAt = pg
.timestamp('created_at', { mode: 'date', precision: 3 })
.defaultNow()
export const updatedAt = pg
.timestamp('updated_at', { mode: 'date', precision: 3 })
.$onUpdate(() => new Date())
export const id = pg.integer('id').primaryKey({ autoIncrement: true })
export const createdAt = timestamp('created_at', { mode: 'date', precision: 3 }).defaultNow()
export const updatedAt = timestamp('updated_at', { mode: 'date', precision: 3 }).$onUpdate(() => new Date())
export const id = serial('id').primaryKey()
export const timestamps = {
createdAt,