You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.7 KiB
77 lines
2.7 KiB
from minibase.app import db, create_app, bcrypt
|
|
from minibase.blueprints.user.models import Users, User_Roles
|
|
from minibase.blueprints.company.models import Companies, Company_types, Company_legal_entities, Industries, Company_relations, Company_status
|
|
from minibase.blueprints.main.models import Notes
|
|
from minibase.blueprints.sensor.models import nbiotDevice, nbiotDeviceArea, nbiotDeviceType, nbiotDeviceStatus
|
|
import csv
|
|
import os
|
|
|
|
app = create_app()
|
|
app.app_context().push()
|
|
|
|
status = db.drop_all()
|
|
status = db.create_all()
|
|
|
|
static_dir = "init/static/"
|
|
|
|
|
|
def uploadCsvOnlyName(table):
|
|
file = static_dir + "csv/" + str(table.__tablename__) + ".csv"
|
|
with open(file) as f:
|
|
reader = csv.reader(f)
|
|
header = next(reader)
|
|
for i in reader:
|
|
kwargs = {column: value for column, value in zip(header, i)}
|
|
new_entry = table(**kwargs)
|
|
db.session.add(new_entry)
|
|
db.session.commit()
|
|
|
|
|
|
def uploadCsv(filename, table):
|
|
with open(filename) as f:
|
|
reader = csv.reader(f)
|
|
header = next(reader)
|
|
for i in reader:
|
|
kwargs = {column: value for column, value in zip(header, i)}
|
|
new_entry = table(**kwargs)
|
|
db.session.add(new_entry)
|
|
db.session.commit()
|
|
|
|
|
|
def initDatabase():
|
|
uploadCsvOnlyName(Companies)
|
|
uploadCsvOnlyName(Company_types)
|
|
uploadCsvOnlyName(Company_status)
|
|
uploadCsvOnlyName(Company_relations)
|
|
uploadCsvOnlyName(Company_legal_entities)
|
|
uploadCsvOnlyName(Industries)
|
|
uploadCsvOnlyName(User_Roles)
|
|
uploadCsvOnlyName(Notes)
|
|
uploadCsvOnlyName(nbiotDeviceStatus)
|
|
uploadCsvOnlyName(nbiotDeviceType)
|
|
uploadCsvOnlyName(nbiotDeviceArea)
|
|
uploadCsvOnlyName(nbiotDevice)
|
|
|
|
hashed_pw = bcrypt.generate_password_hash('pass').decode('utf-8')
|
|
user = Users(username="Admin", email_account="admin@kynsight.com", email_comm="admin@kynsight.com", password=hashed_pw, role_id=1)
|
|
db.session.add(user)
|
|
hashed_pw = bcrypt.generate_password_hash('pass').decode('utf-8')
|
|
user = Users(username="KeremYollu", email_account="kerem.yollu@gmail.com", email_comm="kerem.yollu@gmail.com", password=hashed_pw, role_id=2)
|
|
db.session.add(user)
|
|
hashed_pw = bcrypt.generate_password_hash('pass').decode('utf-8')
|
|
user = Users(username="Kynsight", email_account="kerem.yollu@kynsight.com", email_comm="kerem.yollu@kynsight.com", password=hashed_pw, role_id=3)
|
|
db.session.add(user)
|
|
db.session.commit()
|
|
|
|
|
|
user = type(Users)
|
|
roles = type(User_Roles)
|
|
notes = type(Notes)
|
|
|
|
if __name__ == '__main__':
|
|
initDatabase()
|
|
users=Users.query.all()
|
|
roles=User_Roles.query.all()
|
|
notes=Notes.query.all()
|
|
os.system("sqlite3 instance/test.db < init/static/countries/dump1.sql")
|