diff --git a/common/src/database/schema/postgres/_001_create_subscriptions_table.rs b/common/src/database/schema/postgres/_001_create_subscriptions_table.rs index 3e58582..ddf2a76 100644 --- a/common/src/database/schema/postgres/_001_create_subscriptions_table.rs +++ b/common/src/database/schema/postgres/_001_create_subscriptions_table.rs @@ -20,7 +20,6 @@ impl PostgresMigration for CreateSubscriptionsTable { connection_retry_count INT4, connection_retry_interval INT4, max_time INT4, - max_elements INT4, max_envelope_size INT4, enabled BOOLEAN, read_existing_events BOOLEAN, diff --git a/common/src/database/schema/postgres/_013_add_max_elements_field_in_subscriptions_table.rs b/common/src/database/schema/postgres/_013_add_max_elements_field_in_subscriptions_table.rs new file mode 100644 index 0000000..2bc321f --- /dev/null +++ b/common/src/database/schema/postgres/_013_add_max_elements_field_in_subscriptions_table.rs @@ -0,0 +1,33 @@ +use anyhow::Result; +use async_trait::async_trait; +use deadpool_postgres::Transaction; + +use crate::{database::postgres::PostgresMigration, migration}; + +pub(super) struct AddMaxElementsFieldInSubscriptionsTable; +migration!( + AddMaxElementsFieldInSubscriptionsTable, + 13, + "add max_elements field in subscriptions table" +); + +#[async_trait] +impl PostgresMigration for AddMaxElementsFieldInSubscriptionsTable { + async fn up(&self, tx: &mut Transaction) -> Result<()> { + tx.execute( + "ALTER TABLE subscriptions ADD COLUMN IF NOT EXISTS max_elements INT4;", + &[], + ) + .await?; + Ok(()) + } + + async fn down(&self, tx: &mut Transaction) -> Result<()> { + tx.execute( + "ALTER TABLE subscriptions DROP COLUMN IF EXISTS max_elements", + &[], + ) + .await?; + Ok(()) + } +} diff --git a/common/src/database/schema/postgres/mod.rs b/common/src/database/schema/postgres/mod.rs index 985d626..5b12f95 100644 --- a/common/src/database/schema/postgres/mod.rs +++ b/common/src/database/schema/postgres/mod.rs @@ -14,7 +14,8 @@ use self::{ _009_alter_outputs_format::AlterOutputsFormat, _010_add_revision_field_in_subscriptions_table::AddRevisionFieldInSubscriptionsTable, _011_add_locale_fields_in_subscriptions_table::AddLocaleFieldsInSubscriptionsTable, - _012_alter_outputs_files_config::AlterOutputsFilesConfig + _012_alter_outputs_files_config::AlterOutputsFilesConfig, + _013_add_max_elements_field_in_subscriptions_table::AddMaxElementsFieldInSubscriptionsTable, }; mod _001_create_subscriptions_table; @@ -29,6 +30,7 @@ mod _009_alter_outputs_format; mod _010_add_revision_field_in_subscriptions_table; mod _011_add_locale_fields_in_subscriptions_table; mod _012_alter_outputs_files_config; +mod _013_add_max_elements_field_in_subscriptions_table; pub fn register_migrations(postgres_db: &mut PostgresDatabase) { postgres_db.register_migration(Arc::new(CreateSubscriptionsTable)); @@ -43,4 +45,5 @@ pub fn register_migrations(postgres_db: &mut PostgresDatabase) { postgres_db.register_migration(Arc::new(AddRevisionFieldInSubscriptionsTable)); postgres_db.register_migration(Arc::new(AddLocaleFieldsInSubscriptionsTable)); postgres_db.register_migration(Arc::new(AlterOutputsFilesConfig)); + postgres_db.register_migration(Arc::new(AddMaxElementsFieldInSubscriptionsTable)); } diff --git a/common/src/database/schema/sqlite/_001_create_subscriptions_table.rs b/common/src/database/schema/sqlite/_001_create_subscriptions_table.rs index 7a5f415..735ab83 100644 --- a/common/src/database/schema/sqlite/_001_create_subscriptions_table.rs +++ b/common/src/database/schema/sqlite/_001_create_subscriptions_table.rs @@ -19,7 +19,6 @@ impl SQLiteMigration for CreateSubscriptionsTable { connection_retry_count INTEGER, connection_retry_interval INTEGER, max_time INTEGER, - max_elements INTEGER, max_envelope_size INTEGER, enabled INTEGER, read_existing_events INTEGER, diff --git a/common/src/database/schema/sqlite/_013_add_max_elements_field_in_subscriptions_table.rs b/common/src/database/schema/sqlite/_013_add_max_elements_field_in_subscriptions_table.rs new file mode 100644 index 0000000..1500c5b --- /dev/null +++ b/common/src/database/schema/sqlite/_013_add_max_elements_field_in_subscriptions_table.rs @@ -0,0 +1,26 @@ +use anyhow::{anyhow, Result}; +use rusqlite::Connection; + +use crate::database::sqlite::SQLiteMigration; +use crate::migration; + +pub(super) struct AddMaxElementsFieldInSubscriptionsTable; +migration!( + AddMaxElementsFieldInSubscriptionsTable, + 13, + "add max_elements field in subscriptions table" +); + +impl SQLiteMigration for AddMaxElementsFieldInSubscriptionsTable { + fn up(&self, conn: &Connection) -> Result<()> { + conn.execute("ALTER TABLE subscriptions ADD COLUMN max_elements INTEGER", []) + .map_err(|err| anyhow!("SQLiteError: {}", err))?; + Ok(()) + } + + fn down(&self, conn: &Connection) -> Result<()> { + conn.execute("ALTER TABLE subscriptions DROP COLUMN max_elements", []) + .map_err(|err| anyhow!("SQLiteError: {}", err))?; + Ok(()) + } +} diff --git a/common/src/database/schema/sqlite/mod.rs b/common/src/database/schema/sqlite/mod.rs index 164ff58..c49935c 100644 --- a/common/src/database/schema/sqlite/mod.rs +++ b/common/src/database/schema/sqlite/mod.rs @@ -14,7 +14,8 @@ use self::{ _009_alter_outputs_format::AlterOutputsFormat, _010_add_revision_field_in_subscriptions_table::AddRevisionFieldInSubscriptionsTable, _011_add_locale_fields_in_subscriptions_table::AddLocaleFieldsInSubscriptionsTable, - _012_alter_outputs_files_config::AlterOutputsFilesConfig + _012_alter_outputs_files_config::AlterOutputsFilesConfig, + _013_add_max_elements_field_in_subscriptions_table::AddMaxElementsFieldInSubscriptionsTable, }; mod _001_create_subscriptions_table; @@ -29,6 +30,7 @@ mod _009_alter_outputs_format; mod _010_add_revision_field_in_subscriptions_table; mod _011_add_locale_fields_in_subscriptions_table; mod _012_alter_outputs_files_config; +mod _013_add_max_elements_field_in_subscriptions_table; pub fn register_migrations(sqlite_db: &mut SQLiteDatabase) { sqlite_db.register_migration(Arc::new(CreateSubscriptionsTable)); @@ -43,4 +45,5 @@ pub fn register_migrations(sqlite_db: &mut SQLiteDatabase) { sqlite_db.register_migration(Arc::new(AddRevisionFieldInSubscriptionsTable)); sqlite_db.register_migration(Arc::new(AddLocaleFieldsInSubscriptionsTable)); sqlite_db.register_migration(Arc::new(AlterOutputsFilesConfig)); + sqlite_db.register_migration(Arc::new(AddMaxElementsFieldInSubscriptionsTable)); }