@@ -241,8 +241,9 @@ impl PostgresPersistence {
241
241
}
242
242
client
243
243
. with_retry ( async |client| {
244
- client. batch_execute ( INIT_SQL ) . await ?;
245
- client. batch_execute ( INIT_LEASE_SQL ) . await ?;
244
+ for stmt in INIT_SQL {
245
+ client. batch_execute ( stmt) . await ?;
246
+ }
246
247
Ok ( ( ) )
247
248
} )
248
249
. await ?;
@@ -1552,7 +1553,8 @@ const CREATE_SCHEMA_SQL: &str = r"CREATE SCHEMA IF NOT EXISTS @db_name;";
1552
1553
// This runs (currently) every time a PostgresPersistence is created, so it
1553
1554
// needs to not only be idempotent but not to affect any already-resident data.
1554
1555
// IF NOT EXISTS and ON CONFLICT are helpful.
1555
- const INIT_SQL : & str = r#"
1556
+ const INIT_SQL : & [ & str ] = & [
1557
+ r#"
1556
1558
CREATE TABLE IF NOT EXISTS @db_name.documents (
1557
1559
id BYTEA NOT NULL,
1558
1560
ts BIGINT NOT NULL,
@@ -1566,18 +1568,20 @@ const INIT_SQL: &str = r#"
1566
1568
1567
1569
PRIMARY KEY (ts, table_id, id)
1568
1570
);
1571
+ "# ,
1572
+ r#"
1569
1573
CREATE INDEX IF NOT EXISTS documents_by_table_and_id ON @db_name.documents (
1570
1574
table_id, id, ts
1571
1575
);
1572
1576
CREATE INDEX IF NOT EXISTS documents_by_table_ts_and_id ON @db_name.documents (
1573
1577
table_id, ts, id
1574
1578
);
1575
-
1579
+ "# ,
1580
+ r#"
1576
1581
CREATE TABLE IF NOT EXISTS @db_name.indexes (
1577
1582
/* ids should be serialized as bytes but we keep it compatible with documents */
1578
1583
index_id BYTEA NOT NULL,
1579
1584
ts BIGINT NOT NULL,
1580
-
1581
1585
/*
1582
1586
Postgres maximum primary key length is 2730 bytes, which
1583
1587
is why we split up the key. The first 2500 bytes are stored in key_prefix,
@@ -1600,6 +1604,8 @@ const INIT_SQL: &str = r#"
1600
1604
document_id BYTEA NULL,
1601
1605
PRIMARY KEY (index_id, key_prefix, key_sha256, ts)
1602
1606
);
1607
+ "# ,
1608
+ r#"
1603
1609
/* This index with `ts DESC` enables our "loose index scan" queries
1604
1610
* (i.e. `DISTINCT ON`) to run in both directions, complementing the
1605
1611
* primary key's ts ASC ordering */
@@ -1609,27 +1615,33 @@ const INIT_SQL: &str = r#"
1609
1615
key_sha256,
1610
1616
ts DESC
1611
1617
);
1612
-
1618
+ "# ,
1619
+ r#"
1613
1620
CREATE TABLE IF NOT EXISTS @db_name.leases (
1614
1621
id BIGINT NOT NULL,
1615
1622
ts BIGINT NOT NULL,
1616
1623
1617
1624
PRIMARY KEY (id)
1618
1625
);
1626
+ "# ,
1627
+ r#"
1619
1628
CREATE TABLE IF NOT EXISTS @db_name.read_only (
1620
1629
id BIGINT NOT NULL,
1621
1630
1622
1631
PRIMARY KEY (id)
1623
1632
);
1633
+ "# ,
1634
+ r#"
1624
1635
CREATE TABLE IF NOT EXISTS @db_name.persistence_globals (
1625
1636
key TEXT NOT NULL,
1626
1637
json_value BYTEA NOT NULL,
1627
1638
PRIMARY KEY (key)
1628
- );"# ;
1629
- // We also run this on every initialization, but separate it from INIT_SQL to
1630
- // keep DDL and DML separate.
1631
- const INIT_LEASE_SQL : & str =
1632
- "INSERT INTO @db_name.leases (id, ts) VALUES (1, 0) ON CONFLICT DO NOTHING;" ;
1639
+ );
1640
+ "# ,
1641
+ r#"
1642
+ INSERT INTO @db_name.leases (id, ts) VALUES (1, 0) ON CONFLICT DO NOTHING;
1643
+ "# ,
1644
+ ] ;
1633
1645
const TABLES : & [ & str ] = & [
1634
1646
"documents" ,
1635
1647
"indexes" ,
0 commit comments