1010from core .config import add_db_to_json , load_db_config , save_db_config , write_env_file
1111from core .utils import console , get_free_port , validate_work_dir
1212from templates .compose import (
13+ AGENT_FIREBIRD_SNIPPET ,
1314 AGENT_MARIADB_SNIPPET ,
1415 AGENT_MONGODB_AUTH_SNIPPET ,
1516 AGENT_MONGODB_SNIPPET ,
@@ -75,7 +76,7 @@ def add_db(name: str = typer.Argument(..., help="Name of the agent")):
7576 if category == "SQL" :
7677 db_type = Prompt .ask (
7778 "Type" ,
78- choices = ["postgresql" , "mysql" , "mariadb" , "sqlite" ],
79+ choices = ["postgresql" , "mysql" , "mariadb" , "sqlite" , "firebird" ],
7980 default = "postgresql" ,
8081 )
8182 else :
@@ -98,7 +99,11 @@ def add_db(name: str = typer.Argument(..., help="Name of the agent")):
9899 "Port" ,
99100 default = 5432
100101 if db_type == "postgresql"
101- else (3306 if db_type in ["mysql" , "mariadb" ] else 27017 ),
102+ else (
103+ 3050
104+ if db_type == "firebird"
105+ else (3306 if db_type in ["mysql" , "mariadb" ] else 27017 )
106+ ),
102107 )
103108 user = Prompt .ask ("Username" )
104109 password = Prompt .ask ("Password" , password = True )
@@ -119,7 +124,7 @@ def add_db(name: str = typer.Argument(..., help="Name of the agent")):
119124 if category == "SQL" :
120125 db_engine = Prompt .ask (
121126 "Engine" ,
122- choices = ["postgresql" , "mysql" , "mariadb" , "sqlite" ],
127+ choices = ["postgresql" , "mysql" , "mariadb" , "sqlite" , "firebird" ],
123128 default = "postgresql" ,
124129 )
125130 else :
@@ -246,23 +251,55 @@ def add_db(name: str = typer.Argument(..., help="Name of the agent")):
246251 .replace ("${DB_NAME}" , f"${{{ var_prefix } _DB}}" )
247252 )
248253
254+ elif db_engine == "firebird" :
255+ db_port = get_free_port ()
256+ db_user = "alice"
257+ db_pass = secrets .token_hex (8 )
258+ db_name = "mirror.fdb"
259+ service_name = f"db-firebird-{ secrets .token_hex (2 )} "
260+ var_prefix = service_name .upper ().replace ("-" , "_" )
261+ env_vars [f"{ var_prefix } _PORT" ] = str (db_port )
262+ env_vars [f"{ var_prefix } _DB" ] = db_name
263+ env_vars [f"{ var_prefix } _USER" ] = db_user
264+ env_vars [f"{ var_prefix } _PASS" ] = db_pass
265+ snippet = (
266+ AGENT_FIREBIRD_SNIPPET .replace ("${SERVICE_NAME}" , service_name )
267+ .replace ("${PORT}" , f"${{{ var_prefix } _PORT}}" )
268+ .replace ("${VOL_NAME}" , f"{ service_name } -data" )
269+ .replace ("${DB_NAME}" , f"${{{ var_prefix } _DB}}" )
270+ .replace ("${USER}" , f"${{{ var_prefix } _USER}}" )
271+ .replace ("${PASSWORD}" , f"${{{ var_prefix } _PASS}}" )
272+ )
273+
249274 compose_path = path / "docker-compose.yml"
250275 if compose_path .exists ():
251276 with open (compose_path , "r" ) as f :
252277 content = f .read ()
253278
254- insert_pos = content .find ("networks:" )
255- if insert_pos == - 1 :
279+ if "\n networks:" in content :
280+ insert_pos = content .find ("\n networks:" ) + 1
281+ elif content .startswith ("networks:" ):
282+ insert_pos = 0
283+ else :
256284 insert_pos = len (content )
257285
258286 new_content = content [:insert_pos ] + snippet + "\n " + content [insert_pos :]
259287
260288 vol_snippet = f" { service_name } -data:\n "
261- vol_pos = new_content .find ("volumes:" )
289+
290+ vol_pos = - 1
291+ if "\n volumes:" in new_content :
292+ vol_pos = new_content .find ("\n volumes:" ) + 1
293+ elif new_content .startswith ("volumes:" ):
294+ vol_pos = 0
295+
262296 if vol_pos != - 1 :
263- end_of_volumes = new_content .find ("networks :" , vol_pos )
297+ end_of_volumes = new_content .find ("\n networks :" , vol_pos )
264298 if end_of_volumes == - 1 :
265299 end_of_volumes = len (new_content )
300+ else :
301+ end_of_volumes += 1
302+
266303 new_content = (
267304 new_content [:end_of_volumes ]
268305 + vol_snippet
0 commit comments