Passed
Pull Request — master (#117)
by
unknown
05:28
created

database.preparing   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 4

1 Function

Rating   Name   Duplication   Size   Complexity  
A generate_tables() 0 11 4
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