m20240217_173720_tokenlocation.rs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. use sea_orm_migration::prelude::*;
  2. use crate::db_enums::*;
  3. #[derive(DeriveMigrationName)]
  4. pub struct Migration;
  5. #[async_trait::async_trait]
  6. impl MigrationTrait for Migration {
  7. async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
  8. manager
  9. .create_table(
  10. Table::create()
  11. .table(TokensLocations::Table)
  12. .if_not_exists()
  13. .col(
  14. ColumnDef::new(TokensLocations::Id)
  15. .integer()
  16. .not_null()
  17. .auto_increment()
  18. .primary_key(),
  19. )
  20. .col(
  21. ColumnDef::new(TokensLocations::TokenId)
  22. .integer().not_null().unique_key()
  23. )
  24. .col(
  25. ColumnDef::new(TokensLocations::LocationId)
  26. .integer().not_null().unique_key()
  27. )
  28. .foreign_key(
  29. ForeignKeyCreateStatement::new()
  30. .name("fk_token")
  31. .from(TokensLocations::Table, TokensLocations::TokenId)
  32. .to(UserTokens::Table, UserTokens::Id)
  33. )
  34. .foreign_key(
  35. ForeignKeyCreateStatement::new()
  36. .name("fk_location")
  37. .from(TokensLocations::Table, TokensLocations::LocationId)
  38. .to(Locations::Table, Locations::Id)
  39. )
  40. .to_owned(),
  41. )
  42. .await
  43. }
  44. async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
  45. // Replace the sample below with your own migration scripts
  46. manager
  47. .drop_table(Table::drop().table(TokensLocations::Table).to_owned())
  48. .await
  49. }
  50. }