pr_01m47d15m3e54sn21z27rpy5n9/services/repos/migrations/0002_rfc3339_timestamps.sql

27 lines1,050 bytesCodeBlame
1-- created_at becomes RFC 3339 UTC text instead of Unix seconds.
2PRAGMA defer_foreign_keys = on;
3
4-- Stored in Artifacts as "<namespace>--<name>".
5CREATE TABLE repos_new (
6 id TEXT PRIMARY KEY,
7 namespace TEXT NOT NULL,
8 name TEXT NOT NULL,
9 description TEXT,
10 is_private INTEGER NOT NULL DEFAULT 0,
11 owner_id TEXT NOT NULL,
12 default_branch TEXT NOT NULL DEFAULT 'main',
13 -- Set on an attempt's working copy; those are hidden from listings.
14 -- Refers to this table; the rename below carries the reference along.
15 fork_of TEXT REFERENCES repos_new (id),
16 created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
17 UNIQUE (namespace, name)
18);
19INSERT INTO repos_new
20 (id, namespace, name, description, is_private, owner_id, default_branch, fork_of, created_at)
21SELECT id, namespace, name, description, is_private, owner_id, default_branch, fork_of,
22 strftime('%Y-%m-%dT%H:%M:%fZ', created_at, 'unixepoch')
23FROM repos;
24
25DROP TABLE repos;
26ALTER TABLE repos_new RENAME TO repos;
27CREATE INDEX repos_owner ON repos (owner_id);