rls.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { bigserial, pgSchema, text, timestamp, uuid, varchar } from "../pg-core/index.js";
  2. import { pgRole } from "../pg-core/roles.js";
  3. import { sql } from "../sql/sql.js";
  4. const anonRole = pgRole("anon").existing();
  5. const authenticatedRole = pgRole("authenticated").existing();
  6. const serviceRole = pgRole("service_role").existing();
  7. const postgresRole = pgRole("postgres_role").existing();
  8. const supabaseAuthAdminRole = pgRole("supabase_auth_admin").existing();
  9. const auth = pgSchema("auth");
  10. const authUsers = auth.table("users", {
  11. id: uuid().primaryKey().notNull(),
  12. email: varchar({ length: 255 }),
  13. phone: text().unique(),
  14. emailConfirmedAt: timestamp("email_confirmed_at", { withTimezone: true }),
  15. phoneConfirmedAt: timestamp("phone_confirmed_at", { withTimezone: true }),
  16. lastSignInAt: timestamp("last_sign_in_at", { withTimezone: true }),
  17. createdAt: timestamp("created_at", { withTimezone: true }),
  18. updatedAt: timestamp("updated_at", { withTimezone: true })
  19. });
  20. const realtime = pgSchema("realtime");
  21. const realtimeMessages = realtime.table(
  22. "messages",
  23. {
  24. id: bigserial({ mode: "bigint" }).primaryKey(),
  25. topic: text().notNull(),
  26. extension: text({
  27. enum: ["presence", "broadcast", "postgres_changes"]
  28. }).notNull()
  29. }
  30. );
  31. const authUid = sql`(select auth.uid())`;
  32. const realtimeTopic = sql`realtime.topic()`;
  33. export {
  34. anonRole,
  35. authUid,
  36. authUsers,
  37. authenticatedRole,
  38. postgresRole,
  39. realtimeMessages,
  40. realtimeTopic,
  41. serviceRole,
  42. supabaseAuthAdminRole
  43. };
  44. //# sourceMappingURL=rls.js.map