From 3b4899f78506f6b0fe6359a4a7ab0fdc27e0af27 Mon Sep 17 00:00:00 2001 From: Ultradesu Date: Mon, 6 Jul 2026 10:46:50 +0300 Subject: [PATCH] Fixed migrations --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/sqlite_migration.rs | 2 +- src/vpn.rs | 52 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ad553b4..c87924b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,7 +61,7 @@ checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" [[package]] name = "amnezia-fellow" -version = "0.1.5" +version = "0.1.6" dependencies = [ "async-trait", "base64 0.22.1", diff --git a/Cargo.toml b/Cargo.toml index 518cbff..524fd30 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "amnezia-fellow" -version = "0.1.6" +version = "0.1.7" edition = "2024" description = "Amnezia VPN client manager with SSO, SQLite/PostgreSQL, and Kubernetes Secret sync" diff --git a/src/sqlite_migration.rs b/src/sqlite_migration.rs index b009f4b..e33380b 100644 --- a/src/sqlite_migration.rs +++ b/src/sqlite_migration.rs @@ -146,7 +146,7 @@ async fn copy_app_data(source_db: &Database, target_db: &Database) -> cot::Resul async fn reset_postgres_sequences(db: &Database) -> cot::Result<()> { for table in [ - "cot_session__session", + "cot__session", "amnezia_fellow__user", "amnezia_fellow__oidc_link", "amnezia_fellow__vpn_client", diff --git a/src/vpn.rs b/src/vpn.rs index cbe54d9..09db459 100644 --- a/src/vpn.rs +++ b/src/vpn.rs @@ -1031,7 +1031,57 @@ pub mod db_migrations { &[Operation::custom(create_vpn_client_indexes).build()]; } - pub const MIGRATIONS: &[&SyncDynMigration] = &[&M0005CreateVpnClient, &M0006VpnClientIndexes]; + #[cot::db::migrations::migration_op] + async fn normalize_bigint_ids(ctx: migrations::MigrationContext<'_>) -> cot::db::Result<()> { + if ctx + .db + .raw("SELECT current_setting('server_version_num')") + .await + .is_err() + { + return Ok(()); + } + + for sql in [ + "ALTER TABLE amnezia_fellow__user ALTER COLUMN id TYPE BIGINT", + "ALTER TABLE amnezia_fellow__user \ + ALTER COLUMN telegram_link_code_created_at TYPE BIGINT", + "ALTER TABLE amnezia_fellow__oidc_link ALTER COLUMN id TYPE BIGINT", + "ALTER TABLE amnezia_fellow__oidc_link ALTER COLUMN user_id TYPE BIGINT", + "ALTER TABLE amnezia_fellow__vpn_client ALTER COLUMN id TYPE BIGINT", + "ALTER TABLE amnezia_fellow__vpn_client ALTER COLUMN owner_user_id TYPE BIGINT", + ] { + ctx.db.raw(sql).await?; + } + + Ok(()) + } + + #[derive(Debug, Copy, Clone)] + pub struct M0009NormalizeBigintIds; + + impl migrations::Migration for M0009NormalizeBigintIds { + const APP_NAME: &'static str = "amnezia_fellow"; + const MIGRATION_NAME: &'static str = "m_0009_normalize_bigint_ids"; + const DEPENDENCIES: &'static [migrations::MigrationDependency] = &[ + migrations::MigrationDependency::migration( + "amnezia_fellow", + "m_0006_vpn_client_indexes", + ), + migrations::MigrationDependency::migration( + "amnezia_fellow", + "m_0008_user_telegram_link_code", + ), + ]; + const OPERATIONS: &'static [Operation] = + &[Operation::custom(normalize_bigint_ids).build()]; + } + + pub const MIGRATIONS: &[&SyncDynMigration] = &[ + &M0005CreateVpnClient, + &M0006VpnClientIndexes, + &M0009NormalizeBigintIds, + ]; } #[cfg(test)]