Switch to @vercel/kv
This commit is contained in:
parent
45d3a8d0ee
commit
fc79a708f4
20 changed files with 188 additions and 1079 deletions
|
|
@ -1,19 +0,0 @@
|
|||
import { migrate } from "drizzle-orm/vercel-postgres/migrator";
|
||||
import { db } from "./schema";
|
||||
import * as dotenv from "dotenv";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
// @ts-ignore
|
||||
migrate(db, {
|
||||
migrationsFolder: "lib/db/migrations",
|
||||
})
|
||||
.then(() => {
|
||||
console.log("Migration was succesfull!");
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Migration failed:", err);
|
||||
})
|
||||
.finally(() => {
|
||||
console.info("Migration finished");
|
||||
});
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
CREATE TABLE IF NOT EXISTS "chats" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"role" text NOT NULL,
|
||||
"userId" text NOT NULL,
|
||||
"messages" json DEFAULT '{}'::json NOT NULL
|
||||
);
|
||||
|
|
@ -1 +0,0 @@
|
|||
ALTER TABLE "chats" DROP COLUMN IF EXISTS "messages";
|
||||
|
|
@ -1 +0,0 @@
|
|||
ALTER TABLE "chats" ADD COLUMN "messages" json DEFAULT '{}'::json NOT NULL;
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
{
|
||||
"version": "5",
|
||||
"dialect": "pg",
|
||||
"id": "3bddf21a-46a3-4ee8-8b41-bb79cb80d904",
|
||||
"prevId": "00000000-0000-0000-0000-000000000000",
|
||||
"tables": {
|
||||
"chats": {
|
||||
"name": "chats",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"role": {
|
||||
"name": "role",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"userId": {
|
||||
"name": "userId",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"messages": {
|
||||
"name": "messages",
|
||||
"type": "json",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "'{}'::json"
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {}
|
||||
}
|
||||
},
|
||||
"enums": {},
|
||||
"schemas": {},
|
||||
"_meta": {
|
||||
"schemas": {},
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
{
|
||||
"version": "5",
|
||||
"dialect": "pg",
|
||||
"id": "e8eef642-fc25-4737-8e75-5ad1e8c53b84",
|
||||
"prevId": "3bddf21a-46a3-4ee8-8b41-bb79cb80d904",
|
||||
"tables": {
|
||||
"chats": {
|
||||
"name": "chats",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"role": {
|
||||
"name": "role",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"userId": {
|
||||
"name": "userId",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {}
|
||||
}
|
||||
},
|
||||
"enums": {},
|
||||
"schemas": {},
|
||||
"_meta": {
|
||||
"schemas": {},
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
{
|
||||
"version": "5",
|
||||
"dialect": "pg",
|
||||
"id": "e3f4035a-a940-4529-b037-1737e178d88b",
|
||||
"prevId": "e8eef642-fc25-4737-8e75-5ad1e8c53b84",
|
||||
"tables": {
|
||||
"chats": {
|
||||
"name": "chats",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"role": {
|
||||
"name": "role",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"userId": {
|
||||
"name": "userId",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"messages": {
|
||||
"name": "messages",
|
||||
"type": "json",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "'{}'::json"
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {}
|
||||
}
|
||||
},
|
||||
"enums": {},
|
||||
"schemas": {},
|
||||
"_meta": {
|
||||
"schemas": {},
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
{
|
||||
"version": "5",
|
||||
"dialect": "pg",
|
||||
"entries": [
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "5",
|
||||
"when": 1685719783900,
|
||||
"tag": "0000_fair_groot",
|
||||
"breakpoints": false
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"version": "5",
|
||||
"when": 1685719963202,
|
||||
"tag": "0001_naive_gunslinger",
|
||||
"breakpoints": false
|
||||
},
|
||||
{
|
||||
"idx": 2,
|
||||
"version": "5",
|
||||
"when": 1685720130302,
|
||||
"tag": "0002_striped_purifiers",
|
||||
"breakpoints": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
import { sql } from "@vercel/postgres";
|
||||
import { json, pgTable, text } from "drizzle-orm/pg-core";
|
||||
import { drizzle } from "drizzle-orm/vercel-postgres";
|
||||
|
||||
// const connection = createPool({ connectionString: process.env.POSTGRES_URL });
|
||||
|
||||
export const chats = pgTable("chats", {
|
||||
id: text("id").notNull().primaryKey(),
|
||||
title: text("role").notNull(),
|
||||
userId: text("userId").notNull(),
|
||||
messages: json("messages").notNull().default({}),
|
||||
// .references(() => users.id),
|
||||
});
|
||||
|
||||
// export const messages = pgTable("messages", {
|
||||
// id: text("id").notNull().primaryKey(),
|
||||
// title: text("role").notNull(),
|
||||
// chatId: text("chatId")
|
||||
// .notNull()
|
||||
// .references(() => chats.id),
|
||||
// });
|
||||
|
||||
// export const chatsRelations = relations(chats, ({ many }) => ({
|
||||
// // user: one(users, {
|
||||
// // fields: [chats.userId],
|
||||
// // references: [users.id],
|
||||
// // }),
|
||||
// messages: many(messages),
|
||||
// }));
|
||||
|
||||
// export const messagesRelations = relations(messages, ({ one }) => ({
|
||||
// chat: one(chats, {
|
||||
// fields: [messages.chatId],
|
||||
// references: [chats.id],
|
||||
// }),
|
||||
// }));
|
||||
|
||||
export const db = drizzle(sql, {
|
||||
schema: {
|
||||
// users,
|
||||
// accounts,
|
||||
// sessions,
|
||||
// verificationTokens,
|
||||
chats,
|
||||
// chatsRelations,
|
||||
// messages,
|
||||
// messagesRelations,
|
||||
// usersRelations,
|
||||
},
|
||||
});
|
||||
|
||||
export type DbClient = typeof db;
|
||||
|
||||
export type Schema = {
|
||||
chats: typeof chats;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue