From e27be94619a0d6a6f98036548d72463812426daf Mon Sep 17 00:00:00 2001 From: fabianlindfors Date: Mon, 8 Nov 2021 23:49:49 +0100 Subject: [PATCH] Add primary key to schema We need to know the primary key to perform efficient batch updates. --- src/migrations/create_table.rs | 2 ++ src/schema.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/migrations/create_table.rs b/src/migrations/create_table.rs index 066dbd8..8178c5f 100644 --- a/src/migrations/create_table.rs +++ b/src/migrations/create_table.rs @@ -75,6 +75,8 @@ impl Action for CreateTable { fn update_schema(&self, schema: &mut Schema) -> anyhow::Result<()> { let mut table = Table::new(self.name.to_string()); + table.primary_key = self.primary_key.clone(); + for column in &self.columns { table.add_column(crate::schema::Column { name: column.name.to_string(), diff --git a/src/schema.rs b/src/schema.rs index 3817ef1..41a6217 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -42,6 +42,7 @@ impl Default for Schema { pub struct Table { pub name: String, pub columns: Vec, + pub primary_key: Vec, #[serde(skip)] pub has_is_new: bool, } @@ -50,6 +51,7 @@ impl Table { pub fn new(name: impl Into) -> Table { Table { name: name.into(), + primary_key: vec![], columns: vec![], has_is_new: false, }