ploughshares/docker/ploughshares/init_db.py

44 lines
1.4 KiB
Python

import psycopg2
import os
def init_db():
# Database connection parameters
conn = psycopg2.connect(
host="192.168.1.119",
port=5433,
dbname="testdb",
user="testuser",
password="testpass"
)
conn.autocommit = True
cursor = conn.cursor()
# Read schema file
with open('schema.sql', 'r') as f:
sql_script = f.read()
# Execute schema
cursor.execute(sql_script)
# Insert sample data
cursor.execute('''
INSERT INTO transactions (
transaction_type, company_division, address_1, address_2,
city, province, region, postal_code, is_primary, source_date, source_description,
grant_type, description, amount, recipient, commodity_class, contract_number, comments
) VALUES (
'Subcontract', 'C A E Inc', '5585 Cote de Liesse', 'P O Box 1800',
'ST LAURENT', 'QC', 'Quebec', 'H4T 1G6', true, '2023-08-23', 'Source Description',
'Grant Type', '7000XR Full Flight Simulator (FFS) in Global 6000/6500 configuration (subc)',
0.00, 'US Army', 'Aerospace', 'SUMMARY',
'Subcontract with Leidos, US, through CAE Defense & Security. In support of the High Accuracy Detection and Exploitation System (HADES) program.'
)
''')
cursor.close()
conn.close()
print("Database initialized successfully with sample data.")
if __name__ == "__main__":
init_db()