-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Elizabeth Myers <[email protected]>
- Loading branch information
Showing
20 changed files
with
559 additions
and
110 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* SPDX-License-Identifier: CC0-1.0 | ||
* | ||
* migration/src/m20240312_050549_create_url_filter_table.rs | ||
* | ||
* This file is a component of ShadyURL by Elizabeth Myers. | ||
* | ||
* To the extent possible under law, the person who associated CC0 with | ||
* ShadyURL has waived all copyright and related or neighboring rights | ||
* to ShadyURL. | ||
* | ||
* You should have received a copy of the CC0 legalcode along with this | ||
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. | ||
*/ | ||
|
||
use sea_orm_migration::{prelude::*, schema::*}; | ||
|
||
#[derive(DeriveMigrationName)] | ||
pub struct Migration; | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.create_table( | ||
Table::create() | ||
.table(UrlFilter::Table) | ||
.if_not_exists() | ||
.col( | ||
ColumnDef::new(UrlFilter::Id) | ||
.big_integer() | ||
.primary_key() | ||
.not_null() | ||
.auto_increment(), | ||
) | ||
.col(string(UrlFilter::Filter).not_null().unique_key()) | ||
.col(string(UrlFilter::Reason)) | ||
.col( | ||
ColumnDef::new(UrlFilter::CreatedAt) | ||
.date_time() | ||
.default(Expr::current_timestamp()) | ||
.not_null(), | ||
) | ||
.col(big_integer(UrlFilter::UserCreatedId)) | ||
.foreign_key( | ||
ForeignKeyCreateStatement::new() | ||
.name("fk-url_filter-user_created") | ||
.from(UrlFilter::Table, UrlFilter::UserCreatedId) | ||
.to(User::Table, User::Id) | ||
.on_update(ForeignKeyAction::Cascade) | ||
.on_delete(ForeignKeyAction::SetNull), | ||
) | ||
.to_owned(), | ||
) | ||
.await | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.drop_table(Table::drop().table(UrlFilter::Table).to_owned()) | ||
.await | ||
} | ||
} | ||
|
||
#[derive(DeriveIden)] | ||
enum UrlFilter { | ||
Table, | ||
Id, | ||
Filter, | ||
Reason, | ||
CreatedAt, | ||
UserCreatedId, | ||
} | ||
|
||
#[allow(clippy::enum_variant_names)] | ||
#[derive(Iden)] | ||
enum User { | ||
Table, | ||
Id, | ||
} |
Oops, something went wrong.