1import * as Effect from "effect/Effect";
2import * as SqlClient from "effect/sql/SqlClient";
3
4export default Effect.gen(function* () {
5 const sql = yield* SqlClient.SqlClient;
6 yield* sql`CREATE TABLE auth_devices (
7 device_id TEXT PRIMARY KEY,
8 account_id TEXT NOT NULL,
9 environment_id TEXT,
10 client_json TEXT NOT NULL,
11 created_at INTEGER NOT NULL,
12 expires_at INTEGER NOT NULL,
13 validated_at INTEGER NOT NULL,
14 revoked_at INTEGER
15 )`;
16 yield* sql`CREATE UNIQUE INDEX auth_devices_environment ON auth_devices(environment_id) WHERE environment_id IS NOT NULL AND revoked_at IS NULL`;
17 yield* sql`CREATE TABLE auth_device_refresh (
18 token_hash TEXT PRIMARY KEY,
19 device_id TEXT NOT NULL REFERENCES auth_devices(device_id),
20 expires_at INTEGER NOT NULL,
21 consumed_at INTEGER
22 )`;
23 yield* sql`CREATE INDEX auth_device_refresh_device ON auth_device_refresh(device_id)`;
24 yield* sql`ALTER TABLE auth_sessions ADD COLUMN device_id TEXT REFERENCES auth_devices(device_id)`;
25 yield* sql`CREATE INDEX auth_sessions_device ON auth_sessions(device_id)`;
26});