Skip to content
Snippets Groups Projects
Commit a31068ce authored by Stephen D's avatar Stephen D
Browse files

fix maxxing out the node id seq

parent d7b7011b
No related branches found
No related tags found
No related merge requests found
......@@ -138,7 +138,20 @@ async fn get_nodes(
.unzip();
query!(
"INSERT INTO nodes(name) SELECT UNNEST($1::text[]) ON CONFLICT DO NOTHING;",
r#"
WITH unique_names AS (
SELECT UNNEST($1::text[]) AS name
)
INSERT INTO nodes(name)
SELECT un.name
FROM unique_names un
WHERE NOT EXISTS (
SELECT 1
FROM nodes n
WHERE n.name = un.name
)
ON CONFLICT DO NOTHING;
"#,
&names
)
.execute(&p)
......@@ -429,79 +442,3 @@ async fn populate_tables(
Ok(())
}
async fn create_indexes(pool: &Pool<Postgres>) -> anyhow::Result<()> {
query!("ALTER TABLE nodes_dupe ADD CONSTRAINT nodes_dupe_pkey PRIMARY KEY (id);")
.execute(pool)
.await?;
query!("ALTER TABLE edges_dupe ADD CONSTRAINT edges_dupe_pkey PRIMARY KEY (from_id, to_id);")
.execute(pool)
.await?;
query!("CREATE INDEX nodes_text_idx_dupe ON nodes_dupe(name text_pattern_ops);")
.execute(pool)
.await?;
query!("CREATE INDEX edges_from_id_idx_dupe ON edges_dupe(from_id);")
.execute(pool)
.await?;
query!("CREATE INDEX edges_to_id_idx_dupe ON edges_dupe(to_id);")
.execute(pool)
.await?;
Ok(())
}
async fn swap_tables(pool: &Pool<Postgres>) -> anyhow::Result<()> {
let mut tx = pool.begin().await?;
query!("DROP TABLE nodes").execute(&mut *tx).await?;
query!("DROP TABLE edges").execute(&mut *tx).await?;
query!("ALTER TABLE nodes_dupe RENAME TO nodes")
.execute(&mut *tx)
.await?;
query!("ALTER TABLE edges_dupe RENAME TO edges")
.execute(&mut *tx)
.await?;
query!("ALTER INDEX nodes_text_idx_dupe RENAME TO nodes_text_idx")
.execute(&mut *tx)
.await?;
query!("ALTER INDEX edges_from_id_idx_dupe RENAME TO edges_from_id_idx")
.execute(&mut *tx)
.await?;
query!("ALTER INDEX edges_to_id_idx_dupe RENAME TO edges_to_id_idx")
.execute(&mut *tx)
.await?;
tx.commit().await?;
Ok(())
}
async fn create_tables(pool: &Pool<Postgres>) -> anyhow::Result<()> {
query!(
"
CREATE TABLE nodes_dupe(
id INT NOT NULL,
name TEXT NOT NULL
);
"
)
.execute(pool)
.await?;
query!(
"
CREATE TABLE edges_dupe(
from_id INT NOT NULL,
to_id INT NOT NULL
);
"
)
.execute(pool)
.await?;
Ok(())
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment