Fixes for re-running reset scripts

This commit is contained in:
2025-02-13 10:25:04 -05:00
parent fb9f959fe5
commit f2a5c06005
3 changed files with 550 additions and 591 deletions

View File

@@ -175,8 +175,8 @@ ORDER BY
c.name,
st.vendor;
-- Types are created by the reset script
CREATE TABLE calculate_history (
-- History and status tables
CREATE TABLE IF NOT EXISTS calculate_history (
id BIGSERIAL PRIMARY KEY,
start_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
end_time TIMESTAMP NULL,
@@ -193,24 +193,18 @@ CREATE TABLE calculate_history (
additional_info JSONB
);
CREATE INDEX idx_status_time ON calculate_history(status, start_time);
CREATE TABLE calculate_status (
CREATE TABLE IF NOT EXISTS calculate_status (
module_name module_name PRIMARY KEY,
last_calculation_timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX idx_last_calc ON calculate_status(last_calculation_timestamp);
CREATE TABLE sync_status (
CREATE TABLE IF NOT EXISTS sync_status (
table_name VARCHAR(50) PRIMARY KEY,
last_sync_timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
last_sync_id BIGINT
);
CREATE INDEX idx_last_sync ON sync_status(last_sync_timestamp);
CREATE TABLE import_history (
CREATE TABLE IF NOT EXISTS import_history (
id BIGSERIAL PRIMARY KEY,
table_name VARCHAR(50) NOT NULL,
start_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
@@ -225,5 +219,7 @@ CREATE TABLE import_history (
additional_info JSONB
);
CREATE INDEX idx_table_time ON import_history(table_name, start_time);
CREATE INDEX idx_import_history_status ON import_history(status);
-- Create all indexes after tables are fully created
CREATE INDEX IF NOT EXISTS idx_last_calc ON calculate_status(last_calculation_timestamp);
CREATE INDEX IF NOT EXISTS idx_last_sync ON sync_status(last_sync_timestamp);
CREATE INDEX IF NOT EXISTS idx_table_time ON import_history(table_name, start_time);