Skip to content

Commit fbdc9d9

Browse files
committed
debug: run migrate step for all tables before running indexer
1 parent 43432d4 commit fbdc9d9

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

networks/movement/indexer/src/main.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ use processor::config::processor_config::{DefaultProcessorConfig, ProcessorConfi
66
use processor::config::processor_mode::{BootStrapConfig, ProcessorMode};
77
use processor::processors::ans::ans_processor::AnsProcessorConfig;
88
use processor::processors::token_v2::token_v2_processor::TokenV2ProcessorConfig;
9+
use std::env;
10+
use std::fs;
11+
use std::path::Path;
912
use tokio::task::JoinSet;
1013
//use tokio::time::Duration;
1114
use url::Url;
@@ -14,6 +17,28 @@ mod service;
1417

1518
// const RUNTIME_WORKER_MULTIPLIER: usize = 2;
1619

20+
async fn ensure_migrations_run() -> Result<(), anyhow::Error> {
21+
let lock_file = "/tmp/movement_indexer_migrations.lock";
22+
23+
// Check if migrations have already been run
24+
if Path::new(lock_file).exists() {
25+
tracing::info!("Migrations already completed, skipping...");
26+
return Ok(());
27+
}
28+
29+
// Create lock file to indicate migrations are running
30+
fs::write(lock_file, "migrations_in_progress")?;
31+
32+
// Wait a bit to ensure any other processes see the lock
33+
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
34+
35+
// Update lock file to indicate completion
36+
fs::write(lock_file, "migrations_completed")?;
37+
38+
tracing::info!("Migration lock file created");
39+
Ok(())
40+
}
41+
1742
#[tokio::main]
1843
async fn main() -> Result<(), anyhow::Error> {
1944
let dot_movement = dot_movement::DotMovement::try_from_env()?;
@@ -22,6 +47,17 @@ async fn main() -> Result<(), anyhow::Error> {
2247
let maptos_config =
2348
dot_movement.try_get_config_from_json::<maptos_execution_util::config::Config>()?;
2449

50+
// MIGRATE_ONLY mode: run only one processor for migrations, then exit
51+
if env::var("MIGRATE_ONLY").ok().as_deref() == Some("1") {
52+
let migration_config = build_processor_conf("default_processor", &maptos_config)?;
53+
migration_config.run().await?;
54+
println!("Migrations completed.");
55+
return Ok(());
56+
}
57+
58+
// Ensure migrations are handled properly
59+
ensure_migrations_run().await?;
60+
2561
let mut set = JoinSet::new();
2662

2763
// Create configs for each processor

process-compose/movement-full-node/process-compose.indexer.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: "3"
22

33
processes:
44

5-
build_indexer:
5+
build-indexer:
66
command: |
77
./scripts/services/indexer/build
88
availability:
@@ -20,6 +20,21 @@ processes:
2020
exec:
2121
command: echo "true"
2222

23+
migrate-indexer:
24+
command: |
25+
MIGRATE_ONLY=1 movement-indexer-service
26+
environment:
27+
- RUST_LOG=trace
28+
availability:
29+
restart: exit_on_failure
30+
depends_on:
31+
build-indexer:
32+
condition: process_completed_successfully
33+
postgres:
34+
condition: process_healthy
35+
movement-full-node:
36+
condition: process_healthy
37+
2338
indexer:
2439
command: |
2540
movement-indexer-service
@@ -28,9 +43,11 @@ processes:
2843
exec:
2944
command: curl http://0.0.0.0:8084
3045
depends_on:
31-
build_indexer:
46+
build-indexer:
3247
condition: process_completed_successfully
3348
postgres:
3449
condition: process_healthy
3550
movement-full-node:
3651
condition: process_healthy
52+
migrate-indexer:
53+
condition: process_completed_successfully

0 commit comments

Comments
 (0)