sql.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { sqliteTable, text, integer, primaryKey } from "drizzle-orm/sqlite-core"
  2. import { AccountV2 } from "../account"
  3. import { Timestamps } from "../database/schema.sql"
  4. export const AccountTable = sqliteTable("account", {
  5. id: text().$type<AccountV2.ID>().primaryKey(),
  6. email: text().notNull(),
  7. url: text().notNull(),
  8. access_token: text().$type<AccountV2.AccessToken>().notNull(),
  9. refresh_token: text().$type<AccountV2.RefreshToken>().notNull(),
  10. token_expiry: integer(),
  11. ...Timestamps,
  12. })
  13. export const AccountStateTable = sqliteTable("account_state", {
  14. id: integer().primaryKey(),
  15. active_account_id: text()
  16. .$type<AccountV2.ID>()
  17. .references(() => AccountTable.id, { onDelete: "set null" }),
  18. active_org_id: text().$type<AccountV2.OrgID>(),
  19. })
  20. // LEGACY
  21. export const ControlAccountTable = sqliteTable(
  22. "control_account",
  23. {
  24. email: text().notNull(),
  25. url: text().notNull(),
  26. access_token: text().$type<AccountV2.AccessToken>().notNull(),
  27. refresh_token: text().$type<AccountV2.RefreshToken>().notNull(),
  28. token_expiry: integer(),
  29. active: integer({ mode: "boolean" })
  30. .notNull()
  31. .$default(() => false),
  32. ...Timestamps,
  33. },
  34. (table) => [primaryKey({ columns: [table.email, table.url] })],
  35. )