import type { BackendStatus, BackendType, volumeConfigSchema } from "@ironmount/schemas"; import type { CompressionMode, RepositoryBackend, repositoryConfigSchema, RepositoryStatus, } from "@ironmount/schemas/restic"; import { sql } from "drizzle-orm"; import { int, sqliteTable, text } from "drizzle-orm/sqlite-core"; export const volumesTable = sqliteTable("volumes_table", { id: int().primaryKey({ autoIncrement: true }), name: text().notNull().unique(), type: text().$type().notNull(), status: text().$type().notNull().default("unmounted"), lastError: text("last_error"), lastHealthCheck: int("last_health_check", { mode: "timestamp" }).notNull().default(sql`(unixepoch())`), createdAt: int("created_at", { mode: "timestamp" }).notNull().default(sql`(unixepoch())`), updatedAt: int("updated_at", { mode: "timestamp" }).notNull().default(sql`(unixepoch())`), config: text("config", { mode: "json" }).$type().notNull(), autoRemount: int("auto_remount", { mode: "boolean" }).notNull().default(true), }); export type Volume = typeof volumesTable.$inferSelect; export const usersTable = sqliteTable("users_table", { id: int().primaryKey({ autoIncrement: true }), username: text().notNull().unique(), passwordHash: text("password_hash").notNull(), createdAt: int("created_at", { mode: "timestamp" }).notNull().default(sql`(unixepoch())`), updatedAt: int("updated_at", { mode: "timestamp" }).notNull().default(sql`(unixepoch())`), }); export type User = typeof usersTable.$inferSelect; export const sessionsTable = sqliteTable("sessions_table", { id: text().primaryKey(), userId: int("user_id") .notNull() .references(() => usersTable.id, { onDelete: "cascade" }), expiresAt: int("expires_at", { mode: "timestamp" }).notNull(), createdAt: int("created_at", { mode: "timestamp" }).notNull().default(sql`(unixepoch())`), }); export type Session = typeof sessionsTable.$inferSelect; export const repositoriesTable = sqliteTable("repositories_table", { id: text().primaryKey(), name: text().notNull().unique(), type: text().$type().notNull(), config: text("config", { mode: "json" }).$type().notNull(), compressionMode: text("compression_mode").$type().default("auto"), status: text().$type().default("unknown"), lastChecked: int("last_checked", { mode: "timestamp" }), lastError: text("last_error"), createdAt: int("created_at", { mode: "timestamp" }).notNull().default(sql`(unixepoch())`), updatedAt: int("updated_at", { mode: "timestamp" }).notNull().default(sql`(unixepoch())`), }); export type Repository = typeof repositoriesTable.$inferSelect;