from models import Base, engine, MetricType
from sqlalchemy.orm import Session
import uuid
import os

try:
    os.remove('station_db.db')
except Exception as ex:
    pass

# Create all tables in the engine. This is equivalent to "Create Table"
# statements in raw SQL.
Base.metadata.create_all(engine)

session = Session(engine)

def initialize_metric_types():
    metric_types = [None] * 2

    metric_types[0] = MetricType()
    metric_types[0].id = str(uuid.uuid4())
    metric_types[0].name = 'Temperature'
    metric_types[0].min_value = -50.0
    metric_types[0].max_value = 50.0
    metric_types[0].unit = 'C'

    metric_types[1] = MetricType()
    metric_types[1].id = str(uuid.uuid4())
    metric_types[1].name = 'Humidity'
    metric_types[1].min_value = 0.0
    metric_types[1].max_value = 100.0
    metric_types[1].unit = '%'

    session.add_all(metric_types)

    session.commit()

initialize_metric_types()

from models import Base, engine, MetricType
from sqlalchemy.orm import Session
import uuid
import os

# Create all tables in the engine. This is equivalent to "Create Table"
# statements in raw SQL.
Base.metadata.create_all(engine)

session = Session(engine)

def initialize_metric_types():
    metric_types = [None] * 2

    metric_types[0] = MetricType()
    metric_types[0].id = str(uuid.uuid4())
    metric_types[0].name = 'Temperature'
    metric_types[0].min_value = -50.0
    metric_types[0].max_value = 50.0
    metric_types[0].unit = 'C'

    metric_types[1] = MetricType()
    metric_types[1].id = str(uuid.uuid4())
    metric_types[1].name = 'Humidity'
    metric_types[1].min_value = 0.0
    metric_types[1].max_value = 100.0
    metric_types[1].unit = '%'

    session.add_all(metric_types)

    session.commit()

try:
    os.remove('station_db.db')
except Exception as ex:
    pass

initialize_metric_types()

--- 
+++ 
@@ -2,6 +2,11 @@
 from sqlalchemy.orm import Session
 import uuid
 import os
+
+try:
+    os.remove('station_db.db')
+except Exception as ex:
+    pass
 
 # Create all tables in the engine. This is equivalent to "Create Table"
 # statements in raw SQL.
@@ -30,9 +35,4 @@
 
     session.commit()
 
-try:
-    os.remove('station_db.db')
-except Exception as ex:
-    pass
-
 initialize_metric_types()
Fix for lack of file.

Signed-off-by: Maciej Szankin <33c1fdf481c8e628d4c6db7ea8dc77f49f2fa5d7@szankin.pl>
