mirror of
https://github.com/MikroWizard/docker-compose-deployment.git
synced 2025-06-22 10:33:27 +02:00
feat: Initial commit 🎉
Set up the foundational structure for the MikroWizard deployment repository, including: - Docker Compose configuration for MikroFront, MikroMan, PostgreSQL, and Redis Stack. - `prepare.sh` script for host environment preparation. - Database initialization script (`init-db.sql`). - `.env` template for centralized configuration. This commit marks the beginning of a streamlined deployment process for MikroWizard!
This commit is contained in:
commit
a8f029ee38
80 changed files with 3429 additions and 0 deletions
44
mikroman/initpy.py
Normal file
44
mikroman/initpy.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
import json
|
||||
import psycopg2
|
||||
|
||||
# Step 1: Read connection details from server.json
|
||||
with open('/conf/server-conf.json') as f:
|
||||
config = json.load(f)
|
||||
|
||||
# Step 2: Connect to the PostgreSQL database
|
||||
try:
|
||||
conn = psycopg2.connect(
|
||||
dbname=config['PYSRV_DATABASE_NAME'],
|
||||
user=config['PYSRV_DATABASE_USER'],
|
||||
password=config['PYSRV_DATABASE_PASSWORD'],
|
||||
host=config['PYSRV_DATABASE_HOST_POSTGRESQL'],
|
||||
port=config['PYSRV_DATABASE_PORT']
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
print("Connected to the database successfully.")
|
||||
|
||||
# Step 3: Read the SQL commands from the SQL file
|
||||
with open('init.sql', 'r') as sql_file:
|
||||
sql_commands = sql_file.read()
|
||||
|
||||
# Step 4: Execute the SQL commands
|
||||
cursor.execute(sql_commands)
|
||||
if cursor.description: # Check if there are results
|
||||
# Fetch all results
|
||||
results = cursor.fetchall()
|
||||
# Print each row of results
|
||||
for row in results:
|
||||
print(row)
|
||||
conn.commit() # Commit the changes if it's not a SELECT query
|
||||
print("Executed SQL commands successfully.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
exit(1)
|
||||
finally:
|
||||
# Close the database connection
|
||||
if cursor:
|
||||
cursor.close()
|
||||
if conn:
|
||||
conn.close()
|
||||
print("Database connection closed.")
|
Loading…
Add table
Add a link
Reference in a new issue