Run rustfmt and move cache_report into sync_service.rs
This commit is contained in:
@@ -19,11 +19,23 @@ impl MigrationTrait for Migration {
|
||||
.primary_key(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(TimeEntry::TogglId).big_unsigned().not_null().unique_key())
|
||||
ColumnDef::new(TimeEntry::TogglId)
|
||||
.big_unsigned()
|
||||
.not_null()
|
||||
.unique_key(),
|
||||
)
|
||||
.col(ColumnDef::new(TimeEntry::Description).string().not_null())
|
||||
.col(ColumnDef::new(TimeEntry::ProjectId).big_unsigned())
|
||||
.col(ColumnDef::new(TimeEntry::Start).timestamp_with_time_zone().not_null())
|
||||
.col(ColumnDef::new(TimeEntry::Stop).timestamp_with_time_zone().not_null())
|
||||
.col(
|
||||
ColumnDef::new(TimeEntry::Start)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(TimeEntry::Stop)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(TimeEntry::RawJson).json_binary().not_null())
|
||||
.to_owned(),
|
||||
)
|
||||
@@ -46,5 +58,5 @@ enum TimeEntry {
|
||||
ProjectId,
|
||||
Start,
|
||||
Stop,
|
||||
RawJson
|
||||
RawJson,
|
||||
}
|
||||
|
||||
@@ -20,7 +20,11 @@ impl MigrationTrait for Migration {
|
||||
.col(ColumnDef::new(Client::Name).string().not_null())
|
||||
.col(ColumnDef::new(Client::Archived).boolean().not_null())
|
||||
.col(ColumnDef::new(Client::WorkspaceId).integer().not_null())
|
||||
.col(ColumnDef::new(Client::At).timestamp_with_time_zone().not_null())
|
||||
.col(
|
||||
ColumnDef::new(Client::At)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(Client::ServerDeletedAt).timestamp_with_time_zone())
|
||||
.to_owned(),
|
||||
)
|
||||
@@ -42,5 +46,5 @@ enum Client {
|
||||
Archived,
|
||||
WorkspaceId,
|
||||
At,
|
||||
ServerDeletedAt
|
||||
ServerDeletedAt,
|
||||
}
|
||||
|
||||
@@ -11,8 +11,19 @@ impl MigrationTrait for Migration {
|
||||
Table::create()
|
||||
.table(Project::Table)
|
||||
.if_not_exists()
|
||||
.col(ColumnDef::new(Project::Id).integer().primary_key().auto_increment().not_null())
|
||||
.col(ColumnDef::new(Project::TogglId).big_unsigned().not_null().unique_key())
|
||||
.col(
|
||||
ColumnDef::new(Project::Id)
|
||||
.integer()
|
||||
.primary_key()
|
||||
.auto_increment()
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Project::TogglId)
|
||||
.big_unsigned()
|
||||
.not_null()
|
||||
.unique_key(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Project::WorkspaceId)
|
||||
.big_unsigned()
|
||||
@@ -27,13 +38,15 @@ impl MigrationTrait for Migration {
|
||||
.await?;
|
||||
|
||||
// Create foreign key
|
||||
manager.create_foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("project_client_id")
|
||||
.from(Project::Table, Project::ClientId)
|
||||
.to(Client::Table, Client::Id)
|
||||
.to_owned(),
|
||||
).await?;
|
||||
manager
|
||||
.create_foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("project_client_id")
|
||||
.from(Project::Table, Project::ClientId)
|
||||
.to(Client::Table, Client::Id)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -6,46 +6,55 @@ pub struct Migration;
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager.alter_table(
|
||||
TableAlterStatement::new()
|
||||
.table(Project::Table)
|
||||
.add_column(ColumnDef::new(Project::Color).text())
|
||||
.add_column(ColumnDef::new(Project::ServerCreatedAt).timestamp_with_time_zone())
|
||||
.add_column(ColumnDef::new(Project::ServerUpdatedAt).timestamp_with_time_zone())
|
||||
.add_column(ColumnDef::new(Project::ServerDeletedAt).timestamp_with_time_zone())
|
||||
.to_owned()
|
||||
).await?;
|
||||
manager
|
||||
.alter_table(
|
||||
TableAlterStatement::new()
|
||||
.table(Project::Table)
|
||||
.add_column(ColumnDef::new(Project::Color).text())
|
||||
.add_column(ColumnDef::new(Project::ServerCreatedAt).timestamp_with_time_zone())
|
||||
.add_column(ColumnDef::new(Project::ServerUpdatedAt).timestamp_with_time_zone())
|
||||
.add_column(ColumnDef::new(Project::ServerDeletedAt).timestamp_with_time_zone())
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager.get_connection().execute_unprepared(
|
||||
r#"
|
||||
manager
|
||||
.get_connection()
|
||||
.execute_unprepared(
|
||||
r#"
|
||||
update "project"
|
||||
set "color" = raw_json ->> 'color',
|
||||
"server_created_at" = (raw_json ->> 'created_at') :: timestamptz,
|
||||
"server_updated_at" = (raw_json ->> 'at') :: timestamptz,
|
||||
"server_deleted_at" = (raw_json ->> 'server_deleted_at') :: timestamptz
|
||||
"#,
|
||||
).await?;
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager.alter_table(
|
||||
TableAlterStatement::new()
|
||||
.table(Project::Table)
|
||||
.modify_column(ColumnDef::new(Project::Color).not_null())
|
||||
.modify_column(ColumnDef::new(Project::ServerCreatedAt).not_null())
|
||||
.modify_column(ColumnDef::new(Project::ServerUpdatedAt).not_null())
|
||||
.to_owned()
|
||||
).await
|
||||
manager
|
||||
.alter_table(
|
||||
TableAlterStatement::new()
|
||||
.table(Project::Table)
|
||||
.modify_column(ColumnDef::new(Project::Color).not_null())
|
||||
.modify_column(ColumnDef::new(Project::ServerCreatedAt).not_null())
|
||||
.modify_column(ColumnDef::new(Project::ServerUpdatedAt).not_null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager.alter_table(
|
||||
TableAlterStatement::new()
|
||||
.table(Project::Table)
|
||||
.drop_column(Project::Color)
|
||||
.drop_column(Project::ServerCreatedAt)
|
||||
.drop_column(Project::ServerUpdatedAt)
|
||||
.drop_column(Project::ServerDeletedAt)
|
||||
.to_owned()
|
||||
).await
|
||||
manager
|
||||
.alter_table(
|
||||
TableAlterStatement::new()
|
||||
.table(Project::Table)
|
||||
.drop_column(Project::Color)
|
||||
.drop_column(Project::ServerCreatedAt)
|
||||
.drop_column(Project::ServerUpdatedAt)
|
||||
.drop_column(Project::ServerDeletedAt)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,44 +6,58 @@ pub struct Migration;
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager.alter_table(TableAlterStatement::new()
|
||||
.table(TimeEntry::Table)
|
||||
.add_column(ColumnDef::new(TimeEntry::Tags)
|
||||
.json_binary()
|
||||
.default(serde_json::json!([]))
|
||||
.not_null()
|
||||
manager
|
||||
.alter_table(
|
||||
TableAlterStatement::new()
|
||||
.table(TimeEntry::Table)
|
||||
.add_column(
|
||||
ColumnDef::new(TimeEntry::Tags)
|
||||
.json_binary()
|
||||
.default(serde_json::json!([]))
|
||||
.not_null(),
|
||||
)
|
||||
.add_column(
|
||||
ColumnDef::new(TimeEntry::ServerUpdatedAt).timestamp_with_time_zone(),
|
||||
)
|
||||
.add_column(
|
||||
ColumnDef::new(TimeEntry::ServerDeletedAt).timestamp_with_time_zone(),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.add_column(ColumnDef::new(TimeEntry::ServerUpdatedAt)
|
||||
.timestamp_with_time_zone())
|
||||
.add_column(ColumnDef::new(TimeEntry::ServerDeletedAt)
|
||||
.timestamp_with_time_zone())
|
||||
.to_owned()
|
||||
).await?;
|
||||
.await?;
|
||||
|
||||
manager.get_connection().execute_unprepared(
|
||||
r#"
|
||||
manager
|
||||
.get_connection()
|
||||
.execute_unprepared(
|
||||
r#"
|
||||
update "time_entry"
|
||||
set "tags" = coalesce(raw_json -> 'tags', '[]' :: jsonb),
|
||||
"server_updated_at" = (raw_json ->> 'at') :: timestamptz;
|
||||
"#,
|
||||
).await?;
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager.alter_table(
|
||||
TableAlterStatement::new()
|
||||
.table(TimeEntry::Table)
|
||||
.modify_column(ColumnDef::new(TimeEntry::ServerUpdatedAt).not_null())
|
||||
.to_owned()
|
||||
).await
|
||||
manager
|
||||
.alter_table(
|
||||
TableAlterStatement::new()
|
||||
.table(TimeEntry::Table)
|
||||
.modify_column(ColumnDef::new(TimeEntry::ServerUpdatedAt).not_null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager.alter_table(TableAlterStatement::new()
|
||||
.table(TimeEntry::Table)
|
||||
.drop_column(TimeEntry::Tags)
|
||||
.drop_column(TimeEntry::ServerDeletedAt)
|
||||
.drop_column(TimeEntry::ServerUpdatedAt)
|
||||
.to_owned()
|
||||
).await
|
||||
manager
|
||||
.alter_table(
|
||||
TableAlterStatement::new()
|
||||
.table(TimeEntry::Table)
|
||||
.drop_column(TimeEntry::Tags)
|
||||
.drop_column(TimeEntry::ServerDeletedAt)
|
||||
.drop_column(TimeEntry::ServerUpdatedAt)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user