Skip to content

Commit

Permalink
Insert partitions for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lun4m committed Dec 13, 2024
1 parent a08feee commit 252b168
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
2 changes: 1 addition & 1 deletion db/flags.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ CREATE TABLE IF NOT EXISTS flags.kvdata (
CONSTRAINT unique_kvdata_timeseries_obstime UNIQUE (timeseries, obstime)
);
CREATE INDEX IF NOT EXISTS kvdata_obstime_index ON flags.kvdata (obstime);
CREATE INDEX IF NOT EXISTS kvdata_timeseries_index ON flags.kvdata USING HASH (timeseries);
CREATE INDEX IF NOT EXISTS kvdata_timeseries_index ON flags.kvdata USING HASH (timeseries);
25 changes: 6 additions & 19 deletions integration_tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,6 @@ async fn insert_schema(client: &tokio_postgres::Client, filename: &str) -> Resul
client.batch_execute(schema.as_str()).await
}

fn format_partition(start: &str, end: &str, table: &str) -> String {
// TODO: add multiple partitions?
format!(
"CREATE TABLE {table}_y{start}_to_y{end} PARTITION OF {table} \
FOR VALUES FROM ('{start}-01-01 00:00:00+00') TO ('{end}-01-01 00:00:00+00')",
)
}

async fn create_data_partitions(client: &tokio_postgres::Client) -> Result<(), Error> {
let scalar_string = format_partition("1950", "2100", "public.data");
let nonscalar_string = format_partition("1950", "2100", "public.nonscalar_data");

client.batch_execute(scalar_string.as_str()).await?;
client.batch_execute(nonscalar_string.as_str()).await
}

#[tokio::main]
async fn main() {
let (client, connection) = tokio_postgres::connect(CONNECT_STRING, NoTls)
Expand All @@ -38,10 +22,13 @@ async fn main() {
});

// NOTE: order matters
let schemas = ["db/public.sql", "db/labels.sql", "db/flags.sql"];
let schemas = [
"db/public.sql",
"db/partitions_generated.sql",
"db/labels.sql",
"db/flags.sql",
];
for schema in schemas {
insert_schema(&client, schema).await.unwrap();
}

create_data_partitions(&client).await.unwrap();
}

0 comments on commit 252b168

Please sign in to comment.