Total Complexity | 4 |
Total Lines | 25 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import os |
||
2 | |||
3 | import psycopg2.errors |
||
4 | |||
5 | from database import Database |
||
6 | from database.config import tables |
||
7 | |||
8 | |||
9 | def generate_tables(database): |
||
10 | for (name, table) in tables.items(): |
||
11 | if not database.find_table(name): |
||
12 | try: |
||
13 | database.create_table(name, table) |
||
14 | print(f"Table {name} created.") |
||
15 | except psycopg2.errors.SyntaxError as error: |
||
16 | print(f"Fail: {error}.") |
||
17 | return |
||
18 | else: |
||
19 | print(f"Table {name} already exists.") |
||
20 | |||
21 | |||
22 | if __name__ == "__main__": |
||
23 | db = Database(os.environ["DATABASE_URL"]) |
||
24 | generate_tables(db) |
||
25 |