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

Contracts-lookup extractor #655

Open
wants to merge 4 commits into
base: rimrakhimov/eth-bytecode-db-extractors/extract-workload-queue
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
102 changes: 72 additions & 30 deletions eth-bytecode-db-extractors/Cargo.lock

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

3 changes: 3 additions & 0 deletions eth-bytecode-db-extractors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ members = [
"blockscout",
"blockscout-entity",
"blockscout-migration",
"contracts-lookup",
"contracts-lookup-entity",
"contracts-lookup-migration",
"smart-contract-fiesta",
"smart-contract-fiesta-entity",
"smart-contract-fiesta-migration",
Expand Down
12 changes: 12 additions & 0 deletions eth-bytecode-db-extractors/contracts-lookup-entity/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "contracts-lookup-entity"
version = "0.1.0"
edition = "2021"

[lib]
name = "entity"
path = "src/lib.rs"

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

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

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "contract_addresses")]
pub struct Model {
#[sea_orm(
primary_key,
auto_increment = false,
column_type = "Binary(BlobSize::Blob(None))"
)]
pub contract_address: Vec<u8>,
pub fetched_coin_balance_block_number: Option<i64>,
pub inserted_at: DateTime,
pub updated_at: DateTime,
#[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,
}

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

impl ActiveModelBehavior for ActiveModel {}
7 changes: 7 additions & 0 deletions eth-bytecode-db-extractors/contracts-lookup-entity/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.11

pub mod prelude;

pub mod contract_addresses;

pub use job_queue::entity as job_queue;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.11

pub use super::{contract_addresses::Entity as ContractAddresses, job_queue::Entity as JobQueue};
23 changes: 23 additions & 0 deletions eth-bytecode-db-extractors/contracts-lookup-migration/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "contracts-lookup-migration"
version = "0.1.0"
edition = "2021"
publish = false

[lib]
name = "migration"
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"
features = [
# Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI.
# View the list of supported features at https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime.
# e.g.
"runtime-tokio-rustls", # `ASYNC_RUNTIME` feature
"sqlx-postgres", # `DATABASE_DRIVER` feature
]
41 changes: 41 additions & 0 deletions eth-bytecode-db-extractors/contracts-lookup-migration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Running Migrator CLI

- Generate a new migration file
```sh
cargo run -- generate MIGRATION_NAME
```
- Apply all pending migrations
```sh
cargo run
```
```sh
cargo run -- up
```
- Apply first 10 pending migrations
```sh
cargo run -- up -n 10
```
- Rollback last applied migrations
```sh
cargo run -- down
```
- Rollback last 10 applied migrations
```sh
cargo run -- down -n 10
```
- Drop all tables from the database, then reapply all migrations
```sh
cargo run -- fresh
```
- Rollback all applied migrations, then reapply all migrations
```sh
cargo run -- refresh
```
- Rollback all applied migrations
```sh
cargo run -- reset
```
- Check the status of all migrations
```sh
cargo run -- status
```
32 changes: 32 additions & 0 deletions eth-bytecode-db-extractors/contracts-lookup-migration/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
pub use sea_orm_migration::prelude::*;
use sea_orm_migration::sea_orm::{Statement, TransactionTrait};

mod m20220101_000001_create_contract_addresses_table;

pub struct Migrator;

#[async_trait::async_trait]
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![
Box::new(job_queue::migration::Migration),
Box::new(m20220101_000001_create_contract_addresses_table::Migration),
]
}
}

pub async fn from_statements(
manager: &SchemaManager<'_>,
statements: &[&str],
) -> Result<(), DbErr> {
let txn = manager.get_connection().begin().await?;
for statement in statements {
txn.execute(Statement::from_string(
manager.get_database_backend(),
statement.to_string(),
))
.await
.map_err(|err| DbErr::Migration(format!("{err}\nQuery: {statement}")))?;
}
txn.commit().await
}
Loading
Loading