Auto-update: Thu Jul 25 09:14:46 PDT 2024
This commit is contained in:
parent
e3ef2781b0
commit
f802768053
1 changed files with 17 additions and 17 deletions
|
@ -58,7 +58,7 @@ class Configuration(BaseModel):
|
||||||
if secrets_path:
|
if secrets_path:
|
||||||
with secrets_path.open('r') as file:
|
with secrets_path.open('r') as file:
|
||||||
secrets_data = yaml.safe_load(file)
|
secrets_data = yaml.safe_load(file)
|
||||||
# info(f"Loaded secrets data from {secrets_path}")
|
info(f"Loaded secrets data from {secrets_path}")
|
||||||
if isinstance(config_data, list):
|
if isinstance(config_data, list):
|
||||||
for item in config_data:
|
for item in config_data:
|
||||||
if isinstance(item, dict):
|
if isinstance(item, dict):
|
||||||
|
@ -187,13 +187,13 @@ class APIConfig(BaseModel):
|
||||||
with open(config_path, 'r') as file:
|
with open(config_path, 'r') as file:
|
||||||
config_data = yaml.safe_load(file)
|
config_data = yaml.safe_load(file)
|
||||||
|
|
||||||
info(f"Loaded main config: {config_data}")
|
debug(f"Loaded main config: {config_data}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(secrets_path, 'r') as file:
|
with open(secrets_path, 'r') as file:
|
||||||
secrets_data = yaml.safe_load(file)
|
secrets_data = yaml.safe_load(file)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
err(f"Secrets file not found: {secrets_path}")
|
warn(f"Secrets file not found: {secrets_path}")
|
||||||
secrets_data = {}
|
secrets_data = {}
|
||||||
except yaml.YAMLError as e:
|
except yaml.YAMLError as e:
|
||||||
err(f"Error parsing secrets YAML: {e}")
|
err(f"Error parsing secrets YAML: {e}")
|
||||||
|
@ -214,7 +214,7 @@ class APIConfig(BaseModel):
|
||||||
else:
|
else:
|
||||||
warn(f"Secret key '{secret_key}' not found in secrets file")
|
warn(f"Secret key '{secret_key}' not found in secrets file")
|
||||||
else:
|
else:
|
||||||
err(f"Invalid secret placeholder format: {placeholder}")
|
warn(f"Invalid secret placeholder format: {placeholder}")
|
||||||
|
|
||||||
config_data['MODULES'] = cls._create_dynamic_config(config_data.get('MODULES', {}), 'DynamicModulesConfig')
|
config_data['MODULES'] = cls._create_dynamic_config(config_data.get('MODULES', {}), 'DynamicModulesConfig')
|
||||||
config_data['EXTENSIONS'] = cls._create_dynamic_config(config_data.get('EXTENSIONS', {}), 'DynamicExtensionsConfig')
|
config_data['EXTENSIONS'] = cls._create_dynamic_config(config_data.get('EXTENSIONS', {}), 'DynamicExtensionsConfig')
|
||||||
|
@ -298,7 +298,7 @@ class APIConfig(BaseModel):
|
||||||
if pool_entry is None:
|
if pool_entry is None:
|
||||||
pool_entry = self.local_db
|
pool_entry = self.local_db
|
||||||
|
|
||||||
crit(f"Attempting to connect to database: {pool_entry}")
|
info(f"Attempting to connect to database: {pool_entry}")
|
||||||
try:
|
try:
|
||||||
conn = await asyncpg.connect(
|
conn = await asyncpg.connect(
|
||||||
host=pool_entry['ts_ip'],
|
host=pool_entry['ts_ip'],
|
||||||
|
@ -312,8 +312,8 @@ class APIConfig(BaseModel):
|
||||||
finally:
|
finally:
|
||||||
await conn.close()
|
await conn.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
crit(f"Failed to connect to database: {pool_entry['ts_ip']}:{pool_entry['db_port']}")
|
warn(f"Failed to connect to database: {pool_entry['ts_ip']}:{pool_entry['db_port']}")
|
||||||
crit(f"Error: {str(e)}")
|
err(f"Error: {str(e)}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def initialize_sync(self):
|
async def initialize_sync(self):
|
||||||
|
@ -559,24 +559,24 @@ class APIConfig(BaseModel):
|
||||||
(" NOT NULL" if source_col['is_nullable'] == 'NO' else "") + \
|
(" NOT NULL" if source_col['is_nullable'] == 'NO' else "") + \
|
||||||
(f" DEFAULT {source_col['column_default']}" if source_col['column_default'] else "")
|
(f" DEFAULT {source_col['column_default']}" if source_col['column_default'] else "")
|
||||||
sql = f'ALTER TABLE "{table_name}" ADD COLUMN {col_def}'
|
sql = f'ALTER TABLE "{table_name}" ADD COLUMN {col_def}'
|
||||||
info(f"Executing SQL: {sql}")
|
debug(f"Executing SQL: {sql}")
|
||||||
await conn.execute(sql)
|
await conn.execute(sql)
|
||||||
else:
|
else:
|
||||||
target_col = target_columns[col_name]
|
target_col = target_columns[col_name]
|
||||||
if source_col != target_col:
|
if source_col != target_col:
|
||||||
col_type = get_column_type(source_col['data_type'])
|
col_type = get_column_type(source_col['data_type'])
|
||||||
sql = f'ALTER TABLE "{table_name}" ALTER COLUMN "{col_name}" TYPE {col_type}'
|
sql = f'ALTER TABLE "{table_name}" ALTER COLUMN "{col_name}" TYPE {col_type}'
|
||||||
err(f"Executing SQL: {sql}")
|
debug(f"Executing SQL: {sql}")
|
||||||
await conn.execute(sql)
|
await conn.execute(sql)
|
||||||
if source_col['is_nullable'] != target_col['is_nullable']:
|
if source_col['is_nullable'] != target_col['is_nullable']:
|
||||||
null_constraint = "DROP NOT NULL" if source_col['is_nullable'] == 'YES' else "SET NOT NULL"
|
null_constraint = "DROP NOT NULL" if source_col['is_nullable'] == 'YES' else "SET NOT NULL"
|
||||||
sql = f'ALTER TABLE "{table_name}" ALTER COLUMN "{col_name}" {null_constraint}'
|
sql = f'ALTER TABLE "{table_name}" ALTER COLUMN "{col_name}" {null_constraint}'
|
||||||
info(f"Executing SQL: {sql}")
|
debug(f"Executing SQL: {sql}")
|
||||||
await conn.execute(sql)
|
await conn.execute(sql)
|
||||||
if source_col['column_default'] != target_col['column_default']:
|
if source_col['column_default'] != target_col['column_default']:
|
||||||
default_clause = f"SET DEFAULT {source_col['column_default']}" if source_col['column_default'] else "DROP DEFAULT"
|
default_clause = f"SET DEFAULT {source_col['column_default']}" if source_col['column_default'] else "DROP DEFAULT"
|
||||||
sql = f'ALTER TABLE "{table_name}" ALTER COLUMN "{col_name}" {default_clause}'
|
sql = f'ALTER TABLE "{table_name}" ALTER COLUMN "{col_name}" {default_clause}'
|
||||||
info(f"Executing SQL: {sql}")
|
debug(f"Executing SQL: {sql}")
|
||||||
await conn.execute(sql)
|
await conn.execute(sql)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
err(f"Error processing table {table_name}: {str(e)}")
|
err(f"Error processing table {table_name}: {str(e)}")
|
||||||
|
@ -587,13 +587,13 @@ class APIConfig(BaseModel):
|
||||||
|
|
||||||
for idx_name, idx_def in source_indexes.items():
|
for idx_name, idx_def in source_indexes.items():
|
||||||
if idx_name not in target_indexes:
|
if idx_name not in target_indexes:
|
||||||
info(f"Executing SQL: {idx_def}")
|
debug(f"Executing SQL: {idx_def}")
|
||||||
await conn.execute(idx_def)
|
await conn.execute(idx_def)
|
||||||
elif idx_def != target_indexes[idx_name]:
|
elif idx_def != target_indexes[idx_name]:
|
||||||
sql = f'DROP INDEX IF EXISTS "{idx_name}"'
|
sql = f'DROP INDEX IF EXISTS "{idx_name}"'
|
||||||
info(f"Executing SQL: {sql}")
|
debug(f"Executing SQL: {sql}")
|
||||||
await conn.execute(sql)
|
await conn.execute(sql)
|
||||||
info(f"Executing SQL: {idx_def}")
|
debug(f"Executing SQL: {idx_def}")
|
||||||
await conn.execute(idx_def)
|
await conn.execute(idx_def)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
err(f"Error processing indexes: {str(e)}")
|
err(f"Error processing indexes: {str(e)}")
|
||||||
|
@ -605,14 +605,14 @@ class APIConfig(BaseModel):
|
||||||
for con_name, source_con in source_constraints.items():
|
for con_name, source_con in source_constraints.items():
|
||||||
if con_name not in target_constraints:
|
if con_name not in target_constraints:
|
||||||
sql = f'ALTER TABLE "{source_con["table_name"]}" ADD CONSTRAINT "{con_name}" {source_con["definition"]}'
|
sql = f'ALTER TABLE "{source_con["table_name"]}" ADD CONSTRAINT "{con_name}" {source_con["definition"]}'
|
||||||
info(f"Executing SQL: {sql}")
|
debug(f"Executing SQL: {sql}")
|
||||||
await conn.execute(sql)
|
await conn.execute(sql)
|
||||||
elif source_con != target_constraints[con_name]:
|
elif source_con != target_constraints[con_name]:
|
||||||
sql = f'ALTER TABLE "{source_con["table_name"]}" DROP CONSTRAINT IF EXISTS "{con_name}"'
|
sql = f'ALTER TABLE "{source_con["table_name"]}" DROP CONSTRAINT IF EXISTS "{con_name}"'
|
||||||
info(f"Executing SQL: {sql}")
|
debug(f"Executing SQL: {sql}")
|
||||||
await conn.execute(sql)
|
await conn.execute(sql)
|
||||||
sql = f'ALTER TABLE "{source_con["table_name"]}" ADD CONSTRAINT "{con_name}" {source_con["definition"]}'
|
sql = f'ALTER TABLE "{source_con["table_name"]}" ADD CONSTRAINT "{con_name}" {source_con["definition"]}'
|
||||||
info(f"Executing SQL: {sql}")
|
debug(f"Executing SQL: {sql}")
|
||||||
await conn.execute(sql)
|
await conn.execute(sql)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
err(f"Error processing constraints: {str(e)}")
|
err(f"Error processing constraints: {str(e)}")
|
||||||
|
|
Loading…
Reference in a new issue