-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_tables.txt
67 lines (61 loc) · 3.39 KB
/
create_tables.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import sqlite3
from db_connect import create_connection
connection = create_connection()
def check_for_customer_details_table():
try:
query = (''' SELECT count(name) FROM sqlite_master WHERE type='table' AND name='customer_details' ''')
execute_query = connection.execute(query).fetchone()
if execute_query[0] == 1:
return True
else:
return False
connection.commit()
except Exception as exception:
print("Error customer_details_table: ", exception)
def check_for_customer_balance_table():
try:
query = (''' SELECT count(name) FROM sqlite_master WHERE type='table' AND name='customer_balance' ''')
execute_query = connection.execute(query).fetchone()
if execute_query[0] == 1:
return True
else:
return False
connection.commit()
except Exception as exception:
print("Error customer_balance_table: ", exception)
def check_for_transaction_details_table():
try:
query = (''' SELECT count(name) FROM sqlite_master WHERE type='table' AND name='transaction_details' ''')
execute_query = connection.execute(query).fetchone()
if execute_query[0] == 1:
return True
else:
return False
connection.commit()
except Exception as exception:
print("Error transaction_details_table: ", exception)
def create_tables():
try:
tables = ["customer_details", "customer_balance", "transaction_details"]
for table in tables:
if table == "customer_details" and check_for_customer_details_table():
pass
elif table == "customer_details" and (check_for_customer_details_table() == False):
connection.execute("CREATE TABLE customer_details (id INTEGER, accountNumber char NOT NULL PRIMARY KEY, accountName char NOT NULL, \
currency char NOT NULL, accountOpeningDate char NOT NULL, lastTransactionDate char NOT NULL, accountType char NOT NULL, \
bvn INTEGER NOT NULL, fullname char NOT NULL, phoneNumber INTEGER, email char, status char NOT NULL, createdAt char)")
elif table == "customer_balance" and check_for_customer_balance_table():
pass
elif table == "customer_balance" and (check_for_customer_balance_table() == False):
connection.execute("CREATE TABLE customer_balance (id INTEGER PRIMARY KEY, accountNumber char NOT NULL, currency char NOT NULL, availableBalance INTEGER NOT NULL, \
clearedBalance INTEGER, unclearBalance INTEGER, holdBalance INTEGER, minimumBalance INTEGER, createdAt char)")
elif table == "transaction_details" and check_for_transaction_details_table():
pass
elif table == "transaction_details" and (check_for_transaction_details_table() == False):
connection.execute("CREATE TABLE transaction_details (id INTEGER, accountNumber char NOT NULL, amount INTEGER NOT NULL, currency char NOT NULL, \
channel char, debitOrCredit char NOT NULL, narration char NOT NULL, referenceId char NOT NULL PRIMARY KEY, transactionTime char NOT NULL, \
transactionType char NOT NULL, valueDate char NOT NULL, balanceAfter INTEGER, createdAt char)")
connection.commit()
print("Tables created")
except Exception as exception:
print("Error: ", exception)