Skip to content

Commit 9893924

Browse files
authored
herd-db-upgrade (#657)
* herd-db-upgrade * delay with jitter * simpler, no-txn solution as that causes performance issues * better breaks * idempotent * make gen ? * fiximports * manual fix
1 parent ef86b8a commit 9893924

File tree

71 files changed

+497
-251
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+497
-251
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ gensimple: api-gen go-generate cfgdoc-gen docsgen marketgen docsgen-cli
275275
go mod tidy
276276
.PHONY: gen
277277

278+
fiximports:
279+
$(GOCC) run ./scripts/fiximports
280+
.PHONY: fiximports
281+
278282
forest-test: GOFLAGS+=-tags=forest
279283
forest-test: buildall
280284

harmony/harmonydb/harmonydb.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ retry:
268268
//go:embed sql
269269
var fs embed.FS
270270

271+
var ITestUpgradeFunc func(*pgxpool.Pool, string, string)
272+
271273
func (db *DB) upgrade() error {
272274
// Does the version table exist? if not, make it.
273275
// NOTE: This cannot change except via the next sql file.
@@ -337,6 +339,10 @@ func (db *DB) upgrade() error {
337339
return xerrors.New(msg) // makes devs lives easier by placing message at the end.
338340
}
339341

342+
if ITestUpgradeFunc != nil {
343+
ITestUpgradeFunc(db.pgx, name, megaSql)
344+
}
345+
340346
// Mark Completed.
341347
_, err = db.Exec(context.Background(), "INSERT INTO base (entry) VALUES ($1)", name[:8])
342348
if err != nil {

harmony/harmonydb/sql/20230706-itest_scratch.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CREATE TABLE itest_scratch (
1+
CREATE TABLE IF NOT EXISTS itest_scratch (
22
id SERIAL PRIMARY KEY,
33
content TEXT,
44
some_int INTEGER,

harmony/harmonydb/sql/20230712-sector_index.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
create table sector_location
1+
create table if not exists sector_location
22
(
33
miner_id bigint not null,
44
sector_num bigint not null,
@@ -19,7 +19,7 @@ alter table sector_location
1919
alter table sector_location
2020
alter column read_refs set default 0;
2121

22-
create table storage_path
22+
create table if not exists storage_path
2323
(
2424
"storage_id" varchar not null
2525
constraint "storage_path_pkey"

harmony/harmonydb/sql/20230719-harmony.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* For HarmonyTask base implementation. */
22

3-
CREATE TABLE harmony_machines (
3+
CREATE TABLE IF NOT EXISTS harmony_machines (
44
id SERIAL PRIMARY KEY NOT NULL,
55
last_contact TIMESTAMP NOT NULL DEFAULT current_timestamp,
66
host_and_port varchar(300) NOT NULL,
@@ -9,7 +9,7 @@ CREATE TABLE harmony_machines (
99
gpu FLOAT NOT NULL
1010
);
1111

12-
CREATE TABLE harmony_task (
12+
CREATE TABLE IF NOT EXISTS harmony_task (
1313
id SERIAL PRIMARY KEY NOT NULL,
1414
initiated_by INTEGER,
1515
update_time TIMESTAMP NOT NULL DEFAULT current_timestamp,
@@ -28,7 +28,7 @@ COMMENT ON COLUMN harmony_task.name IS 'The name of the task type.';
2828
COMMENT ON COLUMN harmony_task.owner_id IS 'may be null if between owners or not yet taken';
2929
COMMENT ON COLUMN harmony_task.update_time IS 'When it was last modified. not a heartbeat';
3030

31-
CREATE TABLE harmony_task_history (
31+
CREATE TABLE IF NOT EXISTS harmony_task_history (
3232
id SERIAL PRIMARY KEY NOT NULL,
3333
task_id INTEGER NOT NULL,
3434
name VARCHAR(16) NOT NULL,
@@ -40,14 +40,14 @@ CREATE TABLE harmony_task_history (
4040
);
4141
COMMENT ON COLUMN harmony_task_history.result IS 'Use to detemine if this was a successful run.';
4242

43-
CREATE TABLE harmony_task_follow (
43+
CREATE TABLE IF NOT EXISTS harmony_task_follow (
4444
id SERIAL PRIMARY KEY NOT NULL,
4545
owner_id INTEGER NOT NULL REFERENCES harmony_machines (id) ON DELETE CASCADE,
4646
to_type VARCHAR(16) NOT NULL,
4747
from_type VARCHAR(16) NOT NULL
4848
);
4949

50-
CREATE TABLE harmony_task_impl (
50+
CREATE TABLE IF NOT EXISTS harmony_task_impl (
5151
id SERIAL PRIMARY KEY NOT NULL,
5252
owner_id INTEGER NOT NULL REFERENCES harmony_machines (id) ON DELETE CASCADE,
5353
name VARCHAR(16) NOT NULL

harmony/harmonydb/sql/20230823-wdpost.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
create table wdpost_partition_tasks
1+
create table if not exists wdpost_partition_tasks
22
(
33
task_id bigint not null
44
constraint wdpost_partition_tasks_pk
@@ -17,7 +17,7 @@ comment on column wdpost_partition_tasks.proving_period_start is 'proving period
1717
comment on column wdpost_partition_tasks.deadline_index is 'deadline index within the proving period';
1818
comment on column wdpost_partition_tasks.partition_index is 'partition index within the deadline';
1919

20-
create table wdpost_proofs
20+
create table if not exists wdpost_proofs
2121
(
2222
sp_id bigint not null,
2323
proving_period_start bigint not null,
@@ -34,7 +34,7 @@ create table wdpost_proofs
3434
unique (sp_id, proving_period_start, deadline, partition)
3535
);
3636

37-
create table wdpost_recovery_tasks
37+
create table if not exists wdpost_recovery_tasks
3838
(
3939
task_id bigint not null
4040
constraint wdpost_recovery_tasks_pk

harmony/harmonydb/sql/20230919-config.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CREATE TABLE harmony_config (
1+
CREATE TABLE IF NOT EXISTS harmony_config (
22
id SERIAL PRIMARY KEY NOT NULL,
33
title VARCHAR(300) UNIQUE NOT NULL,
44
config TEXT NOT NULL

harmony/harmonydb/sql/20231103-chain_sends.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
create table message_sends
1+
create table if not exists message_sends
22
(
33
from_key text not null,
44
to_addr text not null,
@@ -37,14 +37,14 @@ comment on column message_sends.send_time is 'time when the send task was execut
3737
comment on column message_sends.send_success is 'whether this message was broadcasted to the network already, null if not yet attempted, true if successful, false if failed';
3838
comment on column message_sends.send_error is 'error message if send_success is false';
3939

40-
create unique index message_sends_success_index
40+
create unique index if not exists message_sends_success_index
4141
on message_sends (from_key, nonce)
4242
where send_success is not false;
4343

4444
comment on index message_sends_success_index is
4545
'message_sends_success_index enforces sender/nonce uniqueness, it is a conditional index that only indexes rows where send_success is not false. This allows us to have multiple rows with the same sender/nonce, as long as only one of them was successfully broadcasted (true) to the network or is in the process of being broadcasted (null).';
4646

47-
create table message_send_locks
47+
create table if not exists message_send_locks
4848
(
4949
from_key text not null,
5050
task_id bigint not null,

harmony/harmonydb/sql/20231110-mining_tasks.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
create table mining_tasks
1+
create table if not exists mining_tasks
22
(
33
task_id bigint not null
44
constraint mining_tasks_pk
@@ -20,7 +20,7 @@ create table mining_tasks
2020
unique (sp_id, epoch)
2121
);
2222

23-
create table mining_base_block
23+
create table if not exists mining_base_block
2424
(
2525
id bigserial not null
2626
constraint mining_base_block_pk
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ALTER TABLE harmony_task_history ADD COLUMN completed_by_host_and_port varchar(300) NOT NULL;
1+
ALTER TABLE harmony_task_history ADD COLUMN IF NOT EXISTS completed_by_host_and_port varchar(300) NOT NULL;

0 commit comments

Comments
 (0)