45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
from extensions import db
|
|
from models.ambiente import Ambiente
|
|
|
|
def seed_ambiente():
|
|
ambientes = [
|
|
# Ambiente 1
|
|
{
|
|
"service_id": 1,
|
|
"service_role_id":4,
|
|
"name": "Entrada",
|
|
"description": " Hall de Entrada, apresenta 3 cameras.",
|
|
"status":"Active"
|
|
},
|
|
|
|
# Ambiente 2
|
|
{
|
|
"service_id": 1,
|
|
"service_role_id":4,
|
|
"name": "Estoque",
|
|
"description": "Estoque, apresenta 3 cameras.",
|
|
"status":"Active"
|
|
},
|
|
]
|
|
for ambiente_data in ambientes:
|
|
# Verifica se já existe um papel para o service_id e name fornecidos
|
|
existing_ambiente = db.session.query(Ambiente).filter_by(
|
|
service_id=ambiente_data["service_id"],
|
|
name=ambiente_data["name"]
|
|
).first()
|
|
|
|
# Se não existe, cria o novo papel
|
|
if not existing_ambiente:
|
|
ambiente = Ambiente(
|
|
service_id=ambiente_data["service_id"],
|
|
service_role_id=ambiente_data["service_role_id"],
|
|
name=ambiente_data["name"],
|
|
description=ambiente_data["description"]
|
|
)
|
|
print("antes do banco")
|
|
db.session.add(ambiente)
|
|
print("adiconei no banco")
|
|
|
|
# Commit a transação para salvar os dados no banco
|
|
db.session.commit()
|