Move to sqlite off cloud
This commit is contained in:
@@ -1,34 +1,27 @@
|
||||
import { relations } from "drizzle-orm";
|
||||
import {
|
||||
pgTable,
|
||||
text,
|
||||
integer,
|
||||
numeric,
|
||||
timestamp,
|
||||
jsonb,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { sqliteTable, text, integer, numeric } from "drizzle-orm/sqlite-core";
|
||||
|
||||
export const users = pgTable("users", {
|
||||
id: integer("id").primaryKey(),
|
||||
export const users = sqliteTable("users", {
|
||||
id: numeric("id").primaryKey(),
|
||||
name: text("name").notNull(),
|
||||
avatar: text("avatar").notNull(),
|
||||
avatar: text("avatar"),
|
||||
city: text("city"),
|
||||
country: text("country"),
|
||||
sex: text("sex"),
|
||||
weight: numeric("weight", {
|
||||
mode: "number",
|
||||
}),
|
||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||
weight: integer("weight"),
|
||||
createdAt: integer("created_at", { mode: "timestamp" })
|
||||
.notNull()
|
||||
.$defaultFn(() => new Date()),
|
||||
});
|
||||
|
||||
export const preferences = pgTable("preferences", {
|
||||
id: integer("id").primaryKey().generatedAlwaysAsIdentity(),
|
||||
userId: integer("user_id")
|
||||
export const preferences = sqliteTable("preferences", {
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
userId: numeric("user_id")
|
||||
.references(() => users.id, {
|
||||
onDelete: "cascade",
|
||||
})
|
||||
.unique(),
|
||||
data: jsonb("data")
|
||||
data: text("data", { mode: "json" })
|
||||
.$type<{
|
||||
enabled: boolean;
|
||||
language: string;
|
||||
@@ -45,19 +38,20 @@ export const preferences = pgTable("preferences", {
|
||||
})),
|
||||
});
|
||||
|
||||
export const tokens = pgTable("tokens", {
|
||||
id: integer("id").primaryKey().generatedAlwaysAsIdentity(),
|
||||
userId: integer("user_id")
|
||||
export const tokens = sqliteTable("tokens", {
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
userId: numeric("user_id")
|
||||
.references(() => users.id, {
|
||||
onDelete: "cascade",
|
||||
})
|
||||
.unique(),
|
||||
refreshToken: text("refresh_token"),
|
||||
accessToken: text("access_token"),
|
||||
expiresAt: timestamp("expires_at").notNull().defaultNow(),
|
||||
expiresAt: integer("expires_at", { mode: "timestamp" })
|
||||
.notNull()
|
||||
.$defaultFn(() => new Date()),
|
||||
});
|
||||
|
||||
// Define relationships
|
||||
export const usersRelations = relations(users, ({ one }) => ({
|
||||
tokens: one(tokens, {
|
||||
fields: [users.id],
|
||||
@@ -69,7 +63,7 @@ export const usersRelations = relations(users, ({ one }) => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
export const referencesRelations = relations(preferences, ({ one }) => ({
|
||||
export const preferencesRelations = relations(preferences, ({ one }) => ({
|
||||
user: one(users, {
|
||||
fields: [preferences.userId],
|
||||
references: [users.id],
|
||||
|
||||
Reference in New Issue
Block a user