-
Notifications
You must be signed in to change notification settings - Fork 3
/
migrations.go
36 lines (31 loc) · 910 Bytes
/
migrations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package pgfs
// Table is the name of the metadata table
// created when [MigrateUp] is called.
const Table = "pgfs_metadata"
// Up is the SQL query executed by [MigrateUp].
const Up = `
CREATE EXTENSION IF NOT EXISTS lo;
CREATE TABLE IF NOT EXISTS pgfs_metadata (
id UUID NOT NULL PRIMARY KEY,
oid OID NOT NULL UNIQUE,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
sys JSONB,
content_type TEXT NOT NULL DEFAULT 'application/octet-stream',
content_size BIGINT NOT NULL,
content_sha256 BYTEA NOT NULL
);
`
// Down is the SQL query executed by [MigrateDown].
const Down = "DROP TABLE pgfs_metadata;"
// MigrateUp executes the SQL query in [Up].
//
// Calling MigrateUp multiple times has no effect.
func MigrateUp(conn Tx) error {
_, err := conn.Exec(Up)
return err
}
// MigrateDown executes the SQL query in [Down].
func MigrateDown(conn Tx) error {
_, err := conn.Exec(Up)
return err
}