@@ -6,6 +6,9 @@ use processor::config::processor_config::{DefaultProcessorConfig, ProcessorConfi
66use processor:: config:: processor_mode:: { BootStrapConfig , ProcessorMode } ;
77use processor:: processors:: ans:: ans_processor:: AnsProcessorConfig ;
88use processor:: processors:: token_v2:: token_v2_processor:: TokenV2ProcessorConfig ;
9+ use std:: env;
10+ use std:: fs;
11+ use std:: path:: Path ;
912use tokio:: task:: JoinSet ;
1013//use tokio::time::Duration;
1114use 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]
1843async 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
0 commit comments