uuid instead of numeric ids

This commit is contained in:
Bryan Stitt 2022-08-04 17:18:54 +00:00
parent be13cb0ff9
commit 33cc2ef5f0

View File

@ -12,10 +12,10 @@ impl MigrationTrait for Migration {
Table::create() Table::create()
.table(User::Table) .table(User::Table)
.col( .col(
ColumnDef::new(User::Id) ColumnDef::new(User::Uuid)
.big_integer() .uuid()
.not_null() .not_null()
.auto_increment() .extra("DEFAULT (UUID_TO_BIN(UUID()))".to_string())
.primary_key(), .primary_key(),
) )
.col( .col(
@ -36,17 +36,13 @@ impl MigrationTrait for Migration {
Table::create() Table::create()
.table(SecondaryUser::Table) .table(SecondaryUser::Table)
.col( .col(
ColumnDef::new(SecondaryUser::Id) ColumnDef::new(SecondaryUser::Uuid)
.big_integer() .uuid()
.not_null() .not_null()
.auto_increment() .extra("DEFAULT (UUID_TO_BIN(UUID()))".to_string())
.primary_key(), .primary_key(),
) )
.col( .col(ColumnDef::new(SecondaryUser::UserId).uuid().not_null())
ColumnDef::new(SecondaryUser::UserId)
.big_integer()
.not_null(),
)
.col( .col(
ColumnDef::new(SecondaryUser::Address) ColumnDef::new(SecondaryUser::Address)
.string_len(42) .string_len(42)
@ -63,15 +59,11 @@ impl MigrationTrait for Migration {
.enumeration("role", ["owner", "admin", "collaborator"]) .enumeration("role", ["owner", "admin", "collaborator"])
.not_null(), .not_null(),
) )
.index( .index(sea_query::Index::create().col(SecondaryUser::Address))
sea_query::Index::create()
.name("idx-secondary_user-address")
.col(SecondaryUser::Address),
)
.foreign_key( .foreign_key(
sea_query::ForeignKey::create() sea_query::ForeignKey::create()
.from(SecondaryUser::Table, SecondaryUser::UserId) .from(SecondaryUser::Table, SecondaryUser::UserId)
.to(User::Table, User::Id), .to(User::Table, User::Uuid),
) )
.to_owned(), .to_owned(),
) )
@ -83,10 +75,10 @@ impl MigrationTrait for Migration {
Table::create() Table::create()
.table(BlockList::Table) .table(BlockList::Table)
.col( .col(
ColumnDef::new(BlockList::Id) ColumnDef::new(BlockList::Uuid)
.big_integer() .uuid()
.not_null() .not_null()
.auto_increment() .extra("DEFAULT (UUID_TO_BIN(UUID()))".to_string())
.primary_key(), .primary_key(),
) )
.col( .col(
@ -106,13 +98,13 @@ impl MigrationTrait for Migration {
Table::create() Table::create()
.table(UserKeys::Table) .table(UserKeys::Table)
.col( .col(
ColumnDef::new(UserKeys::Id) ColumnDef::new(UserKeys::Uuid)
.big_integer() .uuid()
.not_null() .not_null()
.auto_increment() .extra("DEFAULT (UUID_TO_BIN(UUID()))".to_string())
.primary_key(), .primary_key(),
) )
.col(ColumnDef::new(UserKeys::UserId).big_integer().not_null()) .col(ColumnDef::new(UserKeys::UserUuid).uuid().not_null())
.col( .col(
ColumnDef::new(UserKeys::ApiKey) ColumnDef::new(UserKeys::ApiKey)
.string_len(32) .string_len(32)
@ -132,15 +124,11 @@ impl MigrationTrait for Migration {
.default(true) .default(true)
.not_null(), .not_null(),
) )
.index( .index(sea_query::Index::create().col(UserKeys::Active))
sea_query::Index::create()
.name("idx-user_keys-active")
.col(UserKeys::Active),
)
.foreign_key( .foreign_key(
sea_query::ForeignKey::create() sea_query::ForeignKey::create()
.from(UserKeys::Table, UserKeys::UserId) .from(UserKeys::Table, UserKeys::UserUuid)
.to(User::Table, User::Id), .to(User::Table, User::Uuid),
) )
.to_owned(), .to_owned(),
) )
@ -172,7 +160,7 @@ impl MigrationTrait for Migration {
#[derive(Iden)] #[derive(Iden)]
enum User { enum User {
Table, Table,
Id, Uuid,
Address, Address,
Description, Description,
Email, Email,
@ -188,7 +176,7 @@ enum User {
#[derive(Iden)] #[derive(Iden)]
enum SecondaryUser { enum SecondaryUser {
Table, Table,
Id, Uuid,
UserId, UserId,
Address, Address,
Description, Description,
@ -200,7 +188,7 @@ enum SecondaryUser {
#[derive(Iden)] #[derive(Iden)]
enum BlockList { enum BlockList {
Table, Table,
Id, Uuid,
Address, Address,
Description, Description,
} }
@ -218,8 +206,8 @@ enum BlockList {
#[derive(Iden)] #[derive(Iden)]
enum UserKeys { enum UserKeys {
Table, Table,
Id, Uuid,
UserId, UserUuid,
ApiKey, ApiKey,
Description, Description,
PrivateTxs, PrivateTxs,