Add support for key length in MySQL
Opened this issue · 0 comments
stevefan1999-personal commented
Motivation
In MySQL BLOB types cannot be primary key directly, and instead you must add a simple type constraint outside to make it a primary key indirectly, although it can still be conveniently done within CREATE TABLE
like the following example:
create table kvstore
(
`key` longblob not null,
value longblob not null,
constraint kvstore_pk
primary key (`key`(3072))
);
Proposed Solutions
Using the aforementioned SQL DDL script, we should have a size constraint on primary_key
which should correspond to:
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "kvstore")]
pub struct Model {
#[sea_orm(
primary_key(size = 3072),
indexed,
auto_increment = false,
column_type = "Binary(BlobSize::Long)"
)]
pub key: Key,
#[sea_orm(nullable = false, column_type = "Binary(BlobSize::Long)")]
pub value: Val,
}
Additional Information
This issue is found by surrealdb/surrealdb#1717, which is trying to use MySQL as a backend database, or let's say all databases that SeaORM supports.