From d7cceab8fc4eacc53ee950473325909326d68fa4 Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Mon, 6 Feb 2023 00:52:16 -0500 Subject: [PATCH] fix: tag table does not have a unique constraint `cargo fmt` on the document. --- src/repo/postgres_migration.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/repo/postgres_migration.rs b/src/repo/postgres_migration.rs index aab2d16..ea49078 100644 --- a/src/repo/postgres_migration.rs +++ b/src/repo/postgres_migration.rs @@ -34,6 +34,7 @@ pub async fn run_migrations(db: &PostgresPool) -> crate::error::Result { if m002_result == MigrationResult::Upgraded { m002::rebuild_tags(db).await?; } + run_migration(m003::migration(), db).await; Ok(current_version(db).await as usize) } @@ -217,3 +218,21 @@ CREATE INDEX tag_value_hex_idx ON tag USING btree (value_hex); Ok(()) } } + +mod m003 { + use crate::repo::postgres_migration::{Migration, SimpleSqlMigration}; + + pub const VERSION: i64 = 3; + + pub fn migration() -> impl Migration { + SimpleSqlMigration { + serial_number: VERSION, + sql: vec![ + r#" +-- Add unique constraint on tag +ALTER TABLE tag ADD CONSTRAINT unique_constraint_name UNIQUE (event_id, "name", value); + "#, + ], + } + } +} \ No newline at end of file