Add create file table, insert first user, fully port to tailwind
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { AttachmentId, PieceId, RequestId, SessionId, Sha256, UserId } from "common";
|
||||
import { ColumnType, CompiledQuery, CreateTableBuilder, Insertable, Kysely, Selectable, sql, Updateable } from "kysely";
|
||||
import { BunSqliteDialect } from "kysely-bun-sqlite";
|
||||
import { Database as BunSqliteDatabase } from "bun:sqlite";
|
||||
import { AttachmentId, PieceId, RequestId, SessionId, Sha256, UserId } from "common";
|
||||
import { ColumnType, CompiledQuery, CreateTableBuilder, Kysely } from "kysely";
|
||||
import { BunSqliteDialect } from "kysely-bun-sqlite";
|
||||
|
||||
export function generateSessionId(byteLength: number = 32): SessionId {
|
||||
const array = new Uint8Array(byteLength);
|
||||
@@ -112,6 +112,13 @@ export async function initDatabase(filename: string = "db.sqlite3"): Promise<Kys
|
||||
.column("timestamp")
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createTable("File")
|
||||
.ifNotExists()
|
||||
.addColumn("sha256", "blob", (c) => c.notNull().primaryKey())
|
||||
.addColumn("data", "blob", (c) => c.notNull())
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createTable("User")
|
||||
.ifNotExists()
|
||||
@@ -152,11 +159,28 @@ export async function initDatabase(filename: string = "db.sqlite3"): Promise<Kys
|
||||
.ifNotExists()
|
||||
.addColumn("attachmentId", "text", (c) => c.notNull().primaryKey())
|
||||
.addColumn("pieceId", "text", (c) => c.notNull().references("Piece.pieceId").onDelete("cascade").onUpdate("cascade"))
|
||||
.addColumn("sha256", "blob", (c) => c.notNull())
|
||||
.addColumn("sha256", "blob", (c) => c.notNull().references("File.sha256").onDelete("restrict").onUpdate("restrict"))
|
||||
.addColumn("filename", "text", (c) => c.notNull())
|
||||
.addColumn("mediaType", "text", (c) => c.notNull())
|
||||
.$call(systemInformation)
|
||||
.execute();
|
||||
|
||||
const { count } = await db
|
||||
.selectFrom("User")
|
||||
.select((eb) => eb.fn.countAll().as("count"))
|
||||
.executeTakeFirstOrThrow();
|
||||
|
||||
if (BigInt(count) === 0n) {
|
||||
const userId = UserId(Bun.randomUUIDv7());
|
||||
const username = "admin";
|
||||
const password = await Bun.password.hash("admin");
|
||||
const admin = 1;
|
||||
|
||||
await db
|
||||
.insertInto("User")
|
||||
.values({ userId, username, password, admin })
|
||||
.execute();
|
||||
}
|
||||
|
||||
return db;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user