From 692bbb00f1ba9b43a10e5cb6a0fcf01c002969ef Mon Sep 17 00:00:00 2001 From: Valentin Tolmer Date: Fri, 13 Jan 2023 15:01:33 +0100 Subject: [PATCH] db: Change the version number from u8 to i16 This is the smallest integer compatible with all of MySQL, Postgres and SQlite. This is a backwards-compatible change for SQlite since both are represented as "integer", and all u8 values can be represented as i16. --- server/src/domain/sql_migrations.rs | 3 ++- server/src/domain/sql_tables.rs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/server/src/domain/sql_migrations.rs b/server/src/domain/sql_migrations.rs index 62d9e59..ff5bb21 100644 --- a/server/src/domain/sql_migrations.rs +++ b/server/src/domain/sql_migrations.rs @@ -116,6 +116,7 @@ pub async fn upgrade_to_v1(pool: &DbConnection) -> std::result::Result<(), sea_o .col( ColumnDef::new(Groups::GroupId) .integer() + .auto_increment() .not_null() .primary_key(), ) @@ -309,7 +310,7 @@ pub async fn upgrade_to_v1(pool: &DbConnection) -> std::result::Result<(), sea_o Table::create() .table(Metadata::Table) .if_not_exists() - .col(ColumnDef::new(Metadata::Version).tiny_integer()), + .col(ColumnDef::new(Metadata::Version).small_integer()), ), ) .await?; diff --git a/server/src/domain/sql_tables.rs b/server/src/domain/sql_tables.rs index af5615a..1bc4f77 100644 --- a/server/src/domain/sql_tables.rs +++ b/server/src/domain/sql_tables.rs @@ -4,7 +4,7 @@ use sea_orm::Value; pub type DbConnection = sea_orm::DatabaseConnection; #[derive(Copy, PartialEq, Eq, Debug, Clone)] -pub struct SchemaVersion(pub u8); +pub struct SchemaVersion(pub i16); impl sea_orm::TryGetable for SchemaVersion { fn try_get( @@ -12,7 +12,7 @@ impl sea_orm::TryGetable for SchemaVersion { pre: &str, col: &str, ) -> Result { - Ok(SchemaVersion(u8::try_get(res, pre, col)?)) + Ok(SchemaVersion(i16::try_get(res, pre, col)?)) } }