diff --git a/store/postgres/migrations/2021-03-12-014815_subgraph_deployment_pkey/down.sql b/store/postgres/migrations/2021-03-12-014815_subgraph_deployment_pkey/down.sql new file mode 100644 index 00000000000..2e467b491fb --- /dev/null +++ b/store/postgres/migrations/2021-03-12-014815_subgraph_deployment_pkey/down.sql @@ -0,0 +1,5 @@ +do $$ +begin + raise 'This migration is irreversible'; +end +$$; diff --git a/store/postgres/migrations/2021-03-12-014815_subgraph_deployment_pkey/up.sql b/store/postgres/migrations/2021-03-12-014815_subgraph_deployment_pkey/up.sql new file mode 100644 index 00000000000..035b518ff5a --- /dev/null +++ b/store/postgres/migrations/2021-03-12-014815_subgraph_deployment_pkey/up.sql @@ -0,0 +1,14 @@ +update subgraphs.subgraph_deployment d + set id = ds.id + from deployment_schemas ds + where ds.subgraph = d.deployment + and d.id is null; + +alter table subgraphs.subgraph_deployment + drop constraint subgraph_deployment_pkey; + +alter table subgraphs.subgraph_deployment + add primary key(id); + +alter table subgraphs.subgraph_deployment + drop column vid; diff --git a/store/postgres/src/deployment.rs b/store/postgres/src/deployment.rs index c6d1da2cf44..5ba7750e468 100644 --- a/store/postgres/src/deployment.rs +++ b/store/postgres/src/deployment.rs @@ -4,7 +4,7 @@ use diesel::{ connection::SimpleConnection, dsl::{delete, insert_into, select, sql, update}, - sql_types::{Integer, Text}, + sql_types::Integer, }; use diesel::{expression::SqlLiteral, pg::PgConnection, sql_types::Numeric}; use diesel::{ @@ -48,8 +48,7 @@ impl From for graph::data::subgraph::schema::SubgraphHealth { } table! { - subgraphs.subgraph_deployment (vid) { - vid -> BigInt, + subgraphs.subgraph_deployment (id) { id -> Integer, deployment -> Text, manifest -> Text, @@ -738,13 +737,13 @@ pub fn update_entity_count( set entity_count = coalesce((nullif(entity_count, -1)) + $1, ({full_count_query})) - where deployment = $2 + where id = $2 ", full_count_query = full_count_query ); Ok(diesel::sql_query(query) .bind::(count) - .bind::(site.deployment.as_str()) + .bind::(site.id) .execute(conn) .map(|_| ())?) } diff --git a/store/postgres/src/detail.rs b/store/postgres/src/detail.rs index 1d7509e4693..f1d53bd1489 100644 --- a/store/postgres/src/detail.rs +++ b/store/postgres/src/detail.rs @@ -25,7 +25,6 @@ type Bytes = Vec; // don't need all the fields #[allow(dead_code)] pub struct DeploymentDetail { - vid: i64, id: i32, pub deployment: String, manifest: String,