🎉 init
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { createClient } from '@libsql/client'
|
||||
import { drizzle } from 'drizzle-orm/libsql'
|
||||
import * as schema from './schema'
|
||||
|
||||
let instance: ReturnType<typeof drizzle<typeof schema>> | undefined
|
||||
|
||||
export function useDb() {
|
||||
if (!instance) {
|
||||
const config = useRuntimeConfig()
|
||||
const client = createClient({
|
||||
url: config.databaseUrl,
|
||||
authToken: config.databaseAuthToken || undefined,
|
||||
})
|
||||
instance = drizzle(client, { schema })
|
||||
}
|
||||
return instance
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
CREATE TABLE `expense_participants` (
|
||||
`expense_id` integer NOT NULL,
|
||||
`participant_id` integer NOT NULL,
|
||||
FOREIGN KEY (`expense_id`) REFERENCES `expenses`(`id`) ON UPDATE no action ON DELETE no action,
|
||||
FOREIGN KEY (`participant_id`) REFERENCES `participants`(`id`) ON UPDATE no action ON DELETE no action
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE INDEX `expense_participants_expense_id_idx` ON `expense_participants` (`expense_id`);--> statement-breakpoint
|
||||
CREATE TABLE `expenses` (
|
||||
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`pot_slug` text NOT NULL,
|
||||
`description` text NOT NULL,
|
||||
`amount_cents` integer NOT NULL,
|
||||
`payer_id` integer NOT NULL,
|
||||
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
|
||||
FOREIGN KEY (`pot_slug`) REFERENCES `pots`(`slug`) ON UPDATE no action ON DELETE no action,
|
||||
FOREIGN KEY (`payer_id`) REFERENCES `participants`(`id`) ON UPDATE no action ON DELETE no action
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE INDEX `expenses_pot_slug_idx` ON `expenses` (`pot_slug`);--> statement-breakpoint
|
||||
CREATE TABLE `participants` (
|
||||
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`pot_slug` text NOT NULL,
|
||||
`name` text NOT NULL,
|
||||
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
|
||||
FOREIGN KEY (`pot_slug`) REFERENCES `pots`(`slug`) ON UPDATE no action ON DELETE no action
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE INDEX `participants_pot_slug_idx` ON `participants` (`pot_slug`);--> statement-breakpoint
|
||||
CREATE TABLE `pots` (
|
||||
`slug` text PRIMARY KEY NOT NULL,
|
||||
`name` text NOT NULL,
|
||||
`currency` text NOT NULL,
|
||||
`created_at` integer DEFAULT (unixepoch()) NOT NULL
|
||||
);
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE `expenses` ADD `type` text DEFAULT 'expense' NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE `participants` ADD `paypal_link` text;
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE `participants` RENAME COLUMN `paypal_link` TO `payment_link`;
|
||||
@@ -0,0 +1,265 @@
|
||||
{
|
||||
"version": "6",
|
||||
"dialect": "sqlite",
|
||||
"id": "c81712c7-479e-4818-9604-5e603434afac",
|
||||
"prevId": "00000000-0000-0000-0000-000000000000",
|
||||
"tables": {
|
||||
"expense_participants": {
|
||||
"name": "expense_participants",
|
||||
"columns": {
|
||||
"expense_id": {
|
||||
"name": "expense_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"participant_id": {
|
||||
"name": "participant_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"expense_participants_expense_id_idx": {
|
||||
"name": "expense_participants_expense_id_idx",
|
||||
"columns": [
|
||||
"expense_id"
|
||||
],
|
||||
"isUnique": false
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"expense_participants_expense_id_expenses_id_fk": {
|
||||
"name": "expense_participants_expense_id_expenses_id_fk",
|
||||
"tableFrom": "expense_participants",
|
||||
"tableTo": "expenses",
|
||||
"columnsFrom": [
|
||||
"expense_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"expense_participants_participant_id_participants_id_fk": {
|
||||
"name": "expense_participants_participant_id_participants_id_fk",
|
||||
"tableFrom": "expense_participants",
|
||||
"tableTo": "participants",
|
||||
"columnsFrom": [
|
||||
"participant_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"expenses": {
|
||||
"name": "expenses",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"pot_slug": {
|
||||
"name": "pot_slug",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"description": {
|
||||
"name": "description",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"amount_cents": {
|
||||
"name": "amount_cents",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"payer_id": {
|
||||
"name": "payer_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(unixepoch())"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"expenses_pot_slug_idx": {
|
||||
"name": "expenses_pot_slug_idx",
|
||||
"columns": [
|
||||
"pot_slug"
|
||||
],
|
||||
"isUnique": false
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"expenses_pot_slug_pots_slug_fk": {
|
||||
"name": "expenses_pot_slug_pots_slug_fk",
|
||||
"tableFrom": "expenses",
|
||||
"tableTo": "pots",
|
||||
"columnsFrom": [
|
||||
"pot_slug"
|
||||
],
|
||||
"columnsTo": [
|
||||
"slug"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"expenses_payer_id_participants_id_fk": {
|
||||
"name": "expenses_payer_id_participants_id_fk",
|
||||
"tableFrom": "expenses",
|
||||
"tableTo": "participants",
|
||||
"columnsFrom": [
|
||||
"payer_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"participants": {
|
||||
"name": "participants",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"pot_slug": {
|
||||
"name": "pot_slug",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(unixepoch())"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"participants_pot_slug_idx": {
|
||||
"name": "participants_pot_slug_idx",
|
||||
"columns": [
|
||||
"pot_slug"
|
||||
],
|
||||
"isUnique": false
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"participants_pot_slug_pots_slug_fk": {
|
||||
"name": "participants_pot_slug_pots_slug_fk",
|
||||
"tableFrom": "participants",
|
||||
"tableTo": "pots",
|
||||
"columnsFrom": [
|
||||
"pot_slug"
|
||||
],
|
||||
"columnsTo": [
|
||||
"slug"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"pots": {
|
||||
"name": "pots",
|
||||
"columns": {
|
||||
"slug": {
|
||||
"name": "slug",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"currency": {
|
||||
"name": "currency",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(unixepoch())"
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
}
|
||||
},
|
||||
"views": {},
|
||||
"enums": {},
|
||||
"_meta": {
|
||||
"schemas": {},
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
},
|
||||
"internal": {
|
||||
"indexes": {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
{
|
||||
"version": "6",
|
||||
"dialect": "sqlite",
|
||||
"id": "ff3f0e2c-da64-4a0c-8c38-7b5717b112ac",
|
||||
"prevId": "c81712c7-479e-4818-9604-5e603434afac",
|
||||
"tables": {
|
||||
"expense_participants": {
|
||||
"name": "expense_participants",
|
||||
"columns": {
|
||||
"expense_id": {
|
||||
"name": "expense_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"participant_id": {
|
||||
"name": "participant_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"expense_participants_expense_id_idx": {
|
||||
"name": "expense_participants_expense_id_idx",
|
||||
"columns": [
|
||||
"expense_id"
|
||||
],
|
||||
"isUnique": false
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"expense_participants_expense_id_expenses_id_fk": {
|
||||
"name": "expense_participants_expense_id_expenses_id_fk",
|
||||
"tableFrom": "expense_participants",
|
||||
"tableTo": "expenses",
|
||||
"columnsFrom": [
|
||||
"expense_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"expense_participants_participant_id_participants_id_fk": {
|
||||
"name": "expense_participants_participant_id_participants_id_fk",
|
||||
"tableFrom": "expense_participants",
|
||||
"tableTo": "participants",
|
||||
"columnsFrom": [
|
||||
"participant_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"expenses": {
|
||||
"name": "expenses",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"pot_slug": {
|
||||
"name": "pot_slug",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"type": {
|
||||
"name": "type",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'expense'"
|
||||
},
|
||||
"description": {
|
||||
"name": "description",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"amount_cents": {
|
||||
"name": "amount_cents",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"payer_id": {
|
||||
"name": "payer_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(unixepoch())"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"expenses_pot_slug_idx": {
|
||||
"name": "expenses_pot_slug_idx",
|
||||
"columns": [
|
||||
"pot_slug"
|
||||
],
|
||||
"isUnique": false
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"expenses_pot_slug_pots_slug_fk": {
|
||||
"name": "expenses_pot_slug_pots_slug_fk",
|
||||
"tableFrom": "expenses",
|
||||
"tableTo": "pots",
|
||||
"columnsFrom": [
|
||||
"pot_slug"
|
||||
],
|
||||
"columnsTo": [
|
||||
"slug"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"expenses_payer_id_participants_id_fk": {
|
||||
"name": "expenses_payer_id_participants_id_fk",
|
||||
"tableFrom": "expenses",
|
||||
"tableTo": "participants",
|
||||
"columnsFrom": [
|
||||
"payer_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"participants": {
|
||||
"name": "participants",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"pot_slug": {
|
||||
"name": "pot_slug",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"paypal_link": {
|
||||
"name": "paypal_link",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(unixepoch())"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"participants_pot_slug_idx": {
|
||||
"name": "participants_pot_slug_idx",
|
||||
"columns": [
|
||||
"pot_slug"
|
||||
],
|
||||
"isUnique": false
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"participants_pot_slug_pots_slug_fk": {
|
||||
"name": "participants_pot_slug_pots_slug_fk",
|
||||
"tableFrom": "participants",
|
||||
"tableTo": "pots",
|
||||
"columnsFrom": [
|
||||
"pot_slug"
|
||||
],
|
||||
"columnsTo": [
|
||||
"slug"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"pots": {
|
||||
"name": "pots",
|
||||
"columns": {
|
||||
"slug": {
|
||||
"name": "slug",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"currency": {
|
||||
"name": "currency",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(unixepoch())"
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
}
|
||||
},
|
||||
"views": {},
|
||||
"enums": {},
|
||||
"_meta": {
|
||||
"schemas": {},
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
},
|
||||
"internal": {
|
||||
"indexes": {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
{
|
||||
"version": "6",
|
||||
"dialect": "sqlite",
|
||||
"id": "f2f62ba6-53b9-43b7-bbd2-3dd5bdaa21fe",
|
||||
"prevId": "ff3f0e2c-da64-4a0c-8c38-7b5717b112ac",
|
||||
"tables": {
|
||||
"expense_participants": {
|
||||
"name": "expense_participants",
|
||||
"columns": {
|
||||
"expense_id": {
|
||||
"name": "expense_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"participant_id": {
|
||||
"name": "participant_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"expense_participants_expense_id_idx": {
|
||||
"name": "expense_participants_expense_id_idx",
|
||||
"columns": [
|
||||
"expense_id"
|
||||
],
|
||||
"isUnique": false
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"expense_participants_expense_id_expenses_id_fk": {
|
||||
"name": "expense_participants_expense_id_expenses_id_fk",
|
||||
"tableFrom": "expense_participants",
|
||||
"tableTo": "expenses",
|
||||
"columnsFrom": [
|
||||
"expense_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"expense_participants_participant_id_participants_id_fk": {
|
||||
"name": "expense_participants_participant_id_participants_id_fk",
|
||||
"tableFrom": "expense_participants",
|
||||
"tableTo": "participants",
|
||||
"columnsFrom": [
|
||||
"participant_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"expenses": {
|
||||
"name": "expenses",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"pot_slug": {
|
||||
"name": "pot_slug",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"type": {
|
||||
"name": "type",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'expense'"
|
||||
},
|
||||
"description": {
|
||||
"name": "description",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"amount_cents": {
|
||||
"name": "amount_cents",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"payer_id": {
|
||||
"name": "payer_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(unixepoch())"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"expenses_pot_slug_idx": {
|
||||
"name": "expenses_pot_slug_idx",
|
||||
"columns": [
|
||||
"pot_slug"
|
||||
],
|
||||
"isUnique": false
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"expenses_pot_slug_pots_slug_fk": {
|
||||
"name": "expenses_pot_slug_pots_slug_fk",
|
||||
"tableFrom": "expenses",
|
||||
"tableTo": "pots",
|
||||
"columnsFrom": [
|
||||
"pot_slug"
|
||||
],
|
||||
"columnsTo": [
|
||||
"slug"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"expenses_payer_id_participants_id_fk": {
|
||||
"name": "expenses_payer_id_participants_id_fk",
|
||||
"tableFrom": "expenses",
|
||||
"tableTo": "participants",
|
||||
"columnsFrom": [
|
||||
"payer_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"participants": {
|
||||
"name": "participants",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"pot_slug": {
|
||||
"name": "pot_slug",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"payment_link": {
|
||||
"name": "payment_link",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(unixepoch())"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"participants_pot_slug_idx": {
|
||||
"name": "participants_pot_slug_idx",
|
||||
"columns": [
|
||||
"pot_slug"
|
||||
],
|
||||
"isUnique": false
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"participants_pot_slug_pots_slug_fk": {
|
||||
"name": "participants_pot_slug_pots_slug_fk",
|
||||
"tableFrom": "participants",
|
||||
"tableTo": "pots",
|
||||
"columnsFrom": [
|
||||
"pot_slug"
|
||||
],
|
||||
"columnsTo": [
|
||||
"slug"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"pots": {
|
||||
"name": "pots",
|
||||
"columns": {
|
||||
"slug": {
|
||||
"name": "slug",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"currency": {
|
||||
"name": "currency",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(unixepoch())"
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
}
|
||||
},
|
||||
"views": {},
|
||||
"enums": {},
|
||||
"_meta": {
|
||||
"schemas": {},
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
},
|
||||
"internal": {
|
||||
"indexes": {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"version": "7",
|
||||
"dialect": "sqlite",
|
||||
"entries": [
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "6",
|
||||
"when": 1782902810997,
|
||||
"tag": "0000_even_shinobi_shaw",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"version": "6",
|
||||
"when": 1782911489463,
|
||||
"tag": "0001_careless_rhodey",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 2,
|
||||
"version": "6",
|
||||
"when": 1782913249404,
|
||||
"tag": "0002_rename_paypal_link",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { sql } from 'drizzle-orm'
|
||||
import { index, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
||||
|
||||
export const pots = sqliteTable('pots', {
|
||||
slug: text('slug').primaryKey(),
|
||||
name: text('name').notNull(),
|
||||
currency: text('currency').notNull(),
|
||||
createdAt: integer('created_at').notNull().default(sql`(unixepoch())`),
|
||||
})
|
||||
|
||||
export const participants = sqliteTable('participants', {
|
||||
id: integer('id').primaryKey({ autoIncrement: true }),
|
||||
potSlug: text('pot_slug').notNull().references(() => pots.slug),
|
||||
name: text('name').notNull(),
|
||||
paymentLink: text('payment_link'),
|
||||
createdAt: integer('created_at').notNull().default(sql`(unixepoch())`),
|
||||
}, table => [
|
||||
index('participants_pot_slug_idx').on(table.potSlug),
|
||||
])
|
||||
|
||||
export const expenses = sqliteTable('expenses', {
|
||||
id: integer('id').primaryKey({ autoIncrement: true }),
|
||||
potSlug: text('pot_slug').notNull().references(() => pots.slug),
|
||||
// 'payment' rows are settlements: payerId is who paid, and the single row
|
||||
// in expenseParticipants is who received it — same shape as a one-person
|
||||
// split expense, which is mathematically what a settlement is.
|
||||
type: text('type').notNull().default('expense'),
|
||||
description: text('description').notNull(),
|
||||
amountCents: integer('amount_cents').notNull(),
|
||||
payerId: integer('payer_id').notNull().references(() => participants.id),
|
||||
createdAt: integer('created_at').notNull().default(sql`(unixepoch())`),
|
||||
}, table => [
|
||||
index('expenses_pot_slug_idx').on(table.potSlug),
|
||||
])
|
||||
|
||||
export const expenseParticipants = sqliteTable('expense_participants', {
|
||||
expenseId: integer('expense_id').notNull().references(() => expenses.id),
|
||||
participantId: integer('participant_id').notNull().references(() => participants.id),
|
||||
}, table => [
|
||||
index('expense_participants_expense_id_idx').on(table.expenseId),
|
||||
])
|
||||
Reference in New Issue
Block a user