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.
This commit is contained in:
Valentin Tolmer 2023-01-13 15:01:33 +01:00 committed by nitnelave
parent 260b545a54
commit 692bbb00f1
2 changed files with 4 additions and 3 deletions

View File

@ -116,6 +116,7 @@ pub async fn upgrade_to_v1(pool: &DbConnection) -> std::result::Result<(), sea_o
.col( .col(
ColumnDef::new(Groups::GroupId) ColumnDef::new(Groups::GroupId)
.integer() .integer()
.auto_increment()
.not_null() .not_null()
.primary_key(), .primary_key(),
) )
@ -309,7 +310,7 @@ pub async fn upgrade_to_v1(pool: &DbConnection) -> std::result::Result<(), sea_o
Table::create() Table::create()
.table(Metadata::Table) .table(Metadata::Table)
.if_not_exists() .if_not_exists()
.col(ColumnDef::new(Metadata::Version).tiny_integer()), .col(ColumnDef::new(Metadata::Version).small_integer()),
), ),
) )
.await?; .await?;

View File

@ -4,7 +4,7 @@ use sea_orm::Value;
pub type DbConnection = sea_orm::DatabaseConnection; pub type DbConnection = sea_orm::DatabaseConnection;
#[derive(Copy, PartialEq, Eq, Debug, Clone)] #[derive(Copy, PartialEq, Eq, Debug, Clone)]
pub struct SchemaVersion(pub u8); pub struct SchemaVersion(pub i16);
impl sea_orm::TryGetable for SchemaVersion { impl sea_orm::TryGetable for SchemaVersion {
fn try_get( fn try_get(
@ -12,7 +12,7 @@ impl sea_orm::TryGetable for SchemaVersion {
pre: &str, pre: &str,
col: &str, col: &str,
) -> Result<Self, sea_orm::TryGetError> { ) -> Result<Self, sea_orm::TryGetError> {
Ok(SchemaVersion(u8::try_get(res, pre, col)?)) Ok(SchemaVersion(i16::try_get(res, pre, col)?))
} }
} }