diff --git a/core/src/database/postgres/generate.rs b/core/src/database/postgres/generate.rs index 302b328..b8929fc 100644 --- a/core/src/database/postgres/generate.rs +++ b/core/src/database/postgres/generate.rs @@ -159,6 +159,7 @@ fn find_clashing_event_names( pub fn generate_tables_for_indexer_sql( project_path: &Path, indexer: &Indexer, + disable_event_tables: bool, ) -> Result { let mut sql = "CREATE SCHEMA IF NOT EXISTS rindexer_internal;".to_string(); @@ -167,20 +168,27 @@ pub fn generate_tables_for_indexer_sql( let abi_items = ABIItem::read_abi_items(project_path, contract)?; let event_names = ABIItem::extract_event_names_and_signatures_from_abi(abi_items)?; let schema_name = generate_indexer_contract_schema_name(&indexer.name, &contract_name); - sql.push_str(format!("CREATE SCHEMA IF NOT EXISTS {};", schema_name).as_str()); - info!("Creating schema if not exists: {}", schema_name); - let networks: Vec<&str> = contract.details.iter().map(|d| d.network.as_str()).collect(); - let event_matching_name_on_other = - find_clashing_event_names(project_path, contract, &indexer.contracts, &event_names)?; - - sql.push_str(&generate_event_table_sql_with_comments( - &event_names, - &contract.name, - &schema_name, - event_matching_name_on_other, - )); + if !disable_event_tables { + sql.push_str(format!("CREATE SCHEMA IF NOT EXISTS {};", schema_name).as_str()); + info!("Creating schema if not exists: {}", schema_name); + + let event_matching_name_on_other = find_clashing_event_names( + project_path, + contract, + &indexer.contracts, + &event_names, + )?; + + sql.push_str(&generate_event_table_sql_with_comments( + &event_names, + &contract.name, + &schema_name, + event_matching_name_on_other, + )); + } + // we still need to create the internal tables for the contract sql.push_str(&generate_internal_event_table_sql(&event_names, &schema_name, networks)); } diff --git a/core/src/database/postgres/setup.rs b/core/src/database/postgres/setup.rs index 0b10925..4b2f826 100644 --- a/core/src/database/postgres/setup.rs +++ b/core/src/database/postgres/setup.rs @@ -30,26 +30,34 @@ pub async fn setup_postgres( info!("Setting up postgres"); let client = PostgresClient::new().await?; - // No-code will ignore this as it must have tables if postgres used - if !manifest.storage.postgres_disable_create_tables() || - manifest.project_type == ProjectType::NoCode - { - // check if we need to drop each run - if manifest.storage.postgres_drop_each_run() { - info!( - "`drop_each_run` enabled so dropping all data for {} before starting", - &manifest.name - ); - let sql = drop_tables_for_indexer_sql(project_path, &manifest.to_indexer()); - client.batch_execute(sql.as_str()).await?; - info!("Dropped all data for {}", manifest.name); - } + let disable_event_tables = manifest.storage.postgres_disable_create_tables(); + + if manifest.storage.postgres_drop_each_run() { + info!( + "`drop_each_run` enabled so dropping all data for {} before starting", + &manifest.name + ); + let sql = drop_tables_for_indexer_sql(project_path, &manifest.to_indexer()); + client.batch_execute(sql.as_str()).await?; + info!("Dropped all data for {}", manifest.name); + } + if !disable_event_tables { info!("Creating tables for {}", manifest.name); - let sql = generate_tables_for_indexer_sql(project_path, &manifest.to_indexer())?; - debug!("{}", sql); - client.batch_execute(sql.as_str()).await?; + } else { + info!("Creating internal rindexer tables for {}", manifest.name); + } + let sql = generate_tables_for_indexer_sql( + project_path, + &manifest.to_indexer(), + disable_event_tables, + )?; + debug!("{}", sql); + client.batch_execute(sql.as_str()).await?; + if !disable_event_tables { info!("Created tables for {}", manifest.name); + } else { + info!("Created internal rindexer tables for {}", manifest.name); } Ok(client) diff --git a/documentation/docs/pages/docs/changelog.mdx b/documentation/docs/pages/docs/changelog.mdx index 5f15239..646cdd5 100644 --- a/documentation/docs/pages/docs/changelog.mdx +++ b/documentation/docs/pages/docs/changelog.mdx @@ -10,6 +10,7 @@ ------------------------------------------------- - fix: pascal case still has some edge cases on parsing - fix: allow #![allow(non_snake_case)] in indexer code +- fix: still generate internal tables for rindexer even if creating new event tables is disabled ### Breaking changes -------------------------------------------------