Skip to content

Commit

Permalink
store: Change the primary key on subgraph_deployment
Browse files Browse the repository at this point in the history
Make 'id' the primary key on subgraph_deployment so that entries there are
identified with the same id as entries in deployment_schemas
  • Loading branch information
lutter committed Mar 19, 2021
1 parent 857dec3 commit 3060635
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
do $$
begin
raise 'This migration is irreversible';
end
$$;
Original file line number Diff line number Diff line change
@@ -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;
9 changes: 4 additions & 5 deletions store/postgres/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -48,8 +48,7 @@ impl From<SubgraphHealth> for graph::data::subgraph::schema::SubgraphHealth {
}

table! {
subgraphs.subgraph_deployment (vid) {
vid -> BigInt,
subgraphs.subgraph_deployment (id) {
id -> Integer,
deployment -> Text,
manifest -> Text,
Expand Down Expand Up @@ -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::<Integer, _>(count)
.bind::<Text, _>(site.deployment.as_str())
.bind::<Integer, _>(site.id)
.execute(conn)
.map(|_| ())?)
}
1 change: 0 additions & 1 deletion store/postgres/src/detail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type Bytes = Vec<u8>;
// don't need all the fields
#[allow(dead_code)]
pub struct DeploymentDetail {
vid: i64,
id: i32,
pub deployment: String,
manifest: String,
Expand Down

0 comments on commit 3060635

Please sign in to comment.