Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth-bytecode-db-extractors - extract job queue #652

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions eth-bytecode-db-extractors/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions eth-bytecode-db-extractors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ members = [
"smart-contract-fiesta",
"smart-contract-fiesta-entity",
"smart-contract-fiesta-migration",
"job-queue",
]
3 changes: 2 additions & 1 deletion eth-bytecode-db-extractors/blockscout-entity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ name = "entity"
path = "src/lib.rs"

[dependencies]
sea-orm = { version = "^0" }
sea-orm = { version = "^0" }
job-queue = { path = "../job-queue", features = ["entity"] }
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2

use super::sea_orm_active_enums::{Language, Status};
use super::sea_orm_active_enums::Language;
use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
Expand All @@ -19,16 +19,30 @@ pub struct Model {
pub verified_at: DateTimeWithTimeZone,
pub language: Language,
pub compiler_version: String,
pub status: Status,
pub log: Option<String>,
#[sea_orm(column_name = "_job_id")]
pub job_id: Uuid,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::job_queue::Entity",
from = "Column::JobId",
to = "super::job_queue::Column::Id",
on_update = "NoAction",
on_delete = "NoAction"
)]
JobQueue,
#[sea_orm(has_many = "super::contract_details::Entity")]
ContractDetails,
}

impl Related<super::job_queue::Entity> for Entity {
fn to() -> RelationDef {
Relation::JobQueue.def()
}
}

impl Related<super::contract_details::Entity> for Entity {
fn to() -> RelationDef {
Relation::ContractDetails.def()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,17 @@ impl Related<super::contract_addresses::Entity> for Entity {
}
}

impl Related<super::job_queue::Entity> for Entity {
fn to() -> RelationDef {
super::contract_addresses::Relation::JobQueue.def()
}
fn via() -> Option<RelationDef> {
Some(
super::contract_addresses::Relation::ContractDetails
.def()
.rev(),
)
}
}

impl ActiveModelBehavior for ActiveModel {}
2 changes: 2 additions & 0 deletions eth-bytecode-db-extractors/blockscout-entity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ pub mod prelude;
pub mod contract_addresses;
pub mod contract_details;
pub mod sea_orm_active_enums;

pub use job_queue::entity as job_queue;
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
pub use super::{
contract_addresses::Entity as ContractAddresses, contract_details::Entity as ContractDetails,
};
pub use job_queue::entity::Entity as JobQueue;
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,3 @@ pub enum Language {
#[sea_orm(string_value = "yul")]
Yul,
}
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "status")]
pub enum Status {
#[sea_orm(string_value = "error")]
Error,
#[sea_orm(string_value = "in_process")]
InProcess,
#[sea_orm(string_value = "success")]
Success,
#[sea_orm(string_value = "waiting")]
Waiting,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2

use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "seaql_migrations")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub version: String,
pub applied_at: i64,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}
Comment on lines +1 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe remove useless codegen?

1 change: 1 addition & 0 deletions eth-bytecode-db-extractors/blockscout-migration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ path = "src/lib.rs"

[dependencies]
async-std = { version = "1", features = ["attributes", "tokio1"] }
job-queue = { path = "../job-queue", features = ["migration"] }

[dependencies.sea-orm-migration]
version = "^0"
Expand Down
3 changes: 1 addition & 2 deletions eth-bytecode-db-extractors/blockscout-migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use sea_orm_migration::sea_orm::{Statement, TransactionTrait};

mod m20230426_170496_create_functions;
mod m20230426_170508_create_language_enum;
mod m20230426_170520_create_status_enum;
mod m20230426_170541_create_contract_addresses_table;
mod m20230426_170553_create_contract_details_table;

Expand All @@ -13,9 +12,9 @@ pub struct Migrator;
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![
Box::new(job_queue::migration::Migration),
Box::new(m20230426_170496_create_functions::Migration),
Box::new(m20230426_170508_create_language_enum::Migration),
Box::new(m20230426_170520_create_status_enum::Migration),
Box::new(m20230426_170541_create_contract_addresses_table::Migration),
Box::new(m20230426_170553_create_contract_details_table::Migration),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let sql = r#"
let create_contract_addresses_table = r#"
CREATE TABLE "contract_addresses" (
"contract_address" bytea NOT NULL,
"chain_id" numeric NOT NULL,
Expand All @@ -18,27 +18,46 @@ impl MigrationTrait for Migration {
"language" language NOT NULL,
"compiler_version" varchar NOT NULL,

"status" status NOT NULL DEFAULT 'waiting',
"log" varchar,
"_job_id" uuid NOT NULL REFERENCES "_job_queue" ("id"),

PRIMARY KEY ("contract_address", "chain_id")
);

"#;
let create_trigger_set_modified_at = r#"
CREATE TRIGGER trigger_set_modified_at
BEFORE INSERT ON contract_addresses
BEFORE UPDATE ON contract_addresses
FOR EACH ROW
EXECUTE FUNCTION set_modified_at();
"#;

crate::from_sql(manager, sql).await
let create_job_queue_connection_statements =
job_queue::migration::create_job_queue_connection_statements("contract_addresses");

let mut statements = vec![
create_contract_addresses_table,
create_trigger_set_modified_at,
];
statements.extend(
create_job_queue_connection_statements
.iter()
.map(|v| v.as_str()),
);

crate::from_statements(manager, &statements).await
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let sql = r#"
DROP TRIGGER trigger_set_modified_at ON contract_addresses;
DROP TABLE contract_addresses;
"#;

crate::from_sql(manager, sql).await
let drop_job_queue_connection_statements =
job_queue::migration::drop_job_queue_connection_statements("contract_addresses");
let drop_trigger_set_modified_at =
"DROP TRIGGER trigger_set_modified_at ON contract_addresses;";
let drop_table_contract_addresses = "DROP TABLE contract_addresses;";

let mut statements = drop_job_queue_connection_statements
.iter()
.map(|v| v.as_str())
.collect::<Vec<_>>();
statements.extend([drop_trigger_set_modified_at, drop_table_contract_addresses]);

crate::from_statements(manager, &statements).await
}
}
1 change: 1 addition & 0 deletions eth-bytecode-db-extractors/blockscout/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
blockscout-entity = { path = "../blockscout-entity" }
blockscout-migration = { path = "../blockscout-migration" }
job-queue = { path = "../job-queue", features = ["logic"] }

anyhow = "1.0.70"
async-trait = "0.1"
Expand Down
Loading
Loading