m20220101_000001_create_table.rs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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(UserTokens::Table)
  12. .if_not_exists()
  13. .col(
  14. ColumnDef::new(UserTokens::Id)
  15. .integer()
  16. .not_null()
  17. .auto_increment()
  18. .primary_key(),
  19. )
  20. .col(ColumnDef::new(UserTokens::Token).text().not_null().unique_key())
  21. .col(ColumnDef::new(UserTokens::ChatId).big_integer().unique_key())
  22. .col(ColumnDef::new(UserTokens::Descr).text().not_null())
  23. .to_owned(),
  24. )
  25. .await?;
  26. manager
  27. .create_table(
  28. Table::create()
  29. .table(Locations::Table)
  30. .if_not_exists()
  31. .col(
  32. ColumnDef::new(Locations::Id)
  33. .integer()
  34. .not_null()
  35. .auto_increment()
  36. .primary_key(),
  37. )
  38. .col(ColumnDef::new(Locations::Endpoint).text().not_null())
  39. .col(ColumnDef::new(Locations::Descr).text().not_null())
  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(UserTokens::Table).to_owned())
  48. .await?;
  49. manager
  50. .drop_table(Table::drop().table(Locations::Table).to_owned())
  51. .await
  52. }
  53. }