updated postgres and mongo updated

This commit is contained in:
2025-04-20 14:21:13 +03:00
parent 71822681f2
commit cc19cb7e6d
85 changed files with 6090 additions and 1986 deletions

View File

@@ -6,16 +6,19 @@ from init_alembic import generate_alembic
from init_occupant_types import create_occupant_types_defaults
from init_services import create_modules_and_services_and_actions
from init_address import create_one_address
from init_occ_defaults import create_occupant_defaults
set_alembic = True
set_alembic = False
if __name__ == "__main__":
with get_db() as db_session:
if set_alembic:
generate_alembic(session=db_session)
create_one_address(db_session=db_session)
init_api_enums_build_types(db_session=db_session)
create_application_defaults(db_session=db_session)
create_occupant_types_defaults(db_session=db_session)
create_modules_and_services_and_actions(db_session=db_session)
create_one_address(db_session=db_session)
create_occupant_defaults(db_session=db_session)

View File

@@ -1,4 +1,5 @@
from Schemas import (
Addresses,
AddressCity,
AddressStreet,
AddressLocality,
@@ -78,6 +79,22 @@ def create_one_address(db_session):
db=db_session,
)
address_list.append(street)
address = Addresses.find_or_create(
street_id=street.id,
street_uu_id=str(street.uu_id),
build_number="Ex1",
door_number="1",
floor_number="1",
comment_address="Example Address",
letter_address="Example Address",
short_letter_address="Example Address",
latitude=0,
longitude=0,
is_confirmed=True,
db=db_session,
)
address_list.append(address)
for address_single in address_list:
address_single.save(db=db_session)
return
if address_single.meta_data.created:
address_single.save(db=db_session)

View File

@@ -50,6 +50,16 @@ def create_application_defaults(db_session):
db=db_session,
)
created_list.append(execution)
gen_man = Departments.find_or_create(
department_name="General Manager Example",
department_code="GM001",
company_id=company_id,
company_uu_id=str(company_uu_id),
**active_row,
db=db_session,
)
created_list.append(gen_man)
it_dept = Departments.find_or_create(
department_name="IT Department",
department_code="ITD001",
@@ -59,6 +69,16 @@ def create_application_defaults(db_session):
db=db_session,
)
created_list.append(it_dept)
gen_duty = Duty.find_or_create(
duty_name="General Manager",
duty_code="GM0001",
duty_description="General Manager",
**active_row,
db=db_session,
)
created_list.append(gen_duty)
bm_duty = Duty.find_or_create(
duty_name="Business Manager",
duty_code="BM0001",
@@ -91,6 +111,19 @@ def create_application_defaults(db_session):
db=db_session,
)
created_list.append(occu_duty)
duties_gen_man = Duties.find_or_create(
company_id=company_id,
company_uu_id=str(company_uu_id),
duties_id=gen_duty.id,
duties_uu_id=str(gen_duty.uu_id),
department_id=gen_man.id,
department_uu_id=str(gen_man.uu_id),
**active_row,
db=db_session,
)
created_list.append(duties_gen_man)
duties_created_bm = Duties.find_or_create(
company_id=company_id,
company_uu_id=str(company_uu_id),
@@ -292,6 +325,24 @@ def create_application_defaults(db_session):
db=db_session,
)
created_list.append(sup_manager)
gen_manager_people = People.find_or_create(
**{
"person_tag": "BM-System",
"firstname": "Example General Manager",
"surname": "Example",
"sex_code": "M",
"middle_name": "",
"father_name": "Father",
"mother_name": "Mother",
"country_code": "TR",
"national_identity_id": "12312312314",
"birth_place": "Ankara",
"birth_date": "01.07.1990",
"tax_no": "1231231233",
},
db=db_session,
)
created_list.append(gen_manager_people)
application_manager_staff = Staff.find_or_create(
staff_description="Application Manager",
staff_name="Application Manager Employee",
@@ -318,6 +369,32 @@ def create_application_defaults(db_session):
db=db_session,
)
created_list.append(super_user_staff)
gen_man_staff = Staff.find_or_create(
staff_description="General Manager",
staff_name="General Manager Employee",
staff_code="GME",
duties_id=duties_gen_man.id,
duties_uu_id=str(gen_duty.uu_id),
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
db=db_session,
)
created_list.append(gen_man_staff)
gen_man_employee = Employees.find_or_create(
staff_id=gen_man_staff.id,
staff_uu_id=str(gen_man_staff.uu_id),
people_id=gen_manager_people.id,
people_uu_id=str(gen_manager_people.uu_id),
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
db=db_session,
)
created_list.append(gen_man_employee)
app_manager_employee = Employees.find_or_create(
staff_id=application_manager_staff.id,
staff_uu_id=str(application_manager_staff.uu_id),
@@ -344,6 +421,38 @@ def create_application_defaults(db_session):
)
created_list.append(super_user_employee)
gen_manager_user = Users.find_or_create(
person_id=gen_manager_people.id,
person_uu_id=str(gen_manager_people.uu_id),
user_tag=gen_manager_people.person_tag,
email="example.general@evyos.com.tr",
phone_number="+901111111111",
avatar="https://s.tmimgcdn.com/scr/800x500/276800/building-home-nature-logo-vector-template-3_276851-original.jpg",
related_company=str(company_management.uu_id),
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
db=db_session,
)
created_list.append(gen_manager_user)
gen_manager_user.password_expiry_begins = str(arrow.now())
gen_manager_user.password_token = PasswordModule.generate_refresher_token()
main_domain, collection_name = (
"evyos.com.tr",
f"{str(company_management.uu_id)}*Domain",
)
with mongo_handler.collection(collection_name) as mongo_engine:
mongo_engine.insert_one(
document={
"user_uu_id": str(gen_manager_user.uu_id),
"other_domains_list": [main_domain],
"main_domain": main_domain,
"modified_at": arrow.now().timestamp(),
}
)
app_manager_user = Users.find_or_create(
person_id=app_manager.id,
person_uu_id=str(app_manager.uu_id),
@@ -362,10 +471,6 @@ def create_application_defaults(db_session):
app_manager_user.password_expiry_begins = str(arrow.now())
app_manager_user.password_token = PasswordModule.generate_refresher_token()
main_domain, collection_name = (
"evyos.com.tr",
f"{str(company_management.uu_id)}*Domain",
)
with mongo_handler.collection(collection_name) as mongo_engine:
mongo_engine.insert_one(
document={

View File

@@ -0,0 +1,314 @@
import arrow
from Modules.Token.password_module import PasswordModule
from Controllers.Mongo.database import mongo_handler
def create_occupant_defaults(db_session):
from Schemas import (
Addresses,
BuildLivingSpace,
Users,
People,
Build,
BuildParts,
BuildTypes,
ApiEnumDropdown,
Companies,
OccupantTypes,
)
created_list = []
company_management = Companies.filter_one(
Companies.formal_name == "Evyos LTD",
db=db_session,
).data
if not company_management:
raise Exception("Company not found")
company_id, company_uu_id = company_management.id, str(company_management.uu_id)
active_row = dict(
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
)
build_type = BuildTypes.filter_one(
BuildTypes.type_code == "APT",
db=db_session,
).data
address = Addresses.filter_one(
Addresses.letter_address == "Example Address",
db=db_session,
).data
created_build = Build.find_or_create(
build_name="Build Example",
build_code="B001",
build_no="B001",
build_date="01.07.1980",
address_id=address.id,
address_uu_id=str(address.uu_id),
company_id=company_id,
build_types_id=build_type.id,
build_types_uu_id=str(build_type.uu_id),
company_uu_id=str(company_uu_id),
**active_row,
db=db_session,
)
created_list.append(created_build)
build_type_created = BuildTypes.filter_one(
BuildTypes.type_code == "APT",
db=db_session,
).data
build_type_flat = BuildTypes.filter_one(
BuildTypes.type_code == "DAIRE",
db=db_session,
).data
enum_dropdown = ApiEnumDropdown.filter_one(
ApiEnumDropdown.key == "NE",
ApiEnumDropdown.enum_class == "Directions",
db=db_session,
).data
occupant_type_prs = OccupantTypes.filter_one(
OccupantTypes.occupant_code == "MT-PRS",
db=db_session,
).data
occupant_type_owner = OccupantTypes.filter_one(
OccupantTypes.occupant_code == "FL-OWN",
db=db_session,
).data
occupant_type_tenant = OccupantTypes.filter_one(
OccupantTypes.occupant_code == "FL-TEN",
db=db_session,
).data
created_managment_room = BuildParts.find_or_create(
address_gov_code="123123123123",
build_id=created_build.id,
build_uu_id=str(created_build.uu_id),
part_code="MR001",
part_net_size=100,
part_no=0,
part_level=0,
part_type_id=build_type_created.id,
part_type_uu_id=str(build_type_created.uu_id),
part_direction_id=enum_dropdown.id,
part_direction_uu_id=str(enum_dropdown.uu_id),
human_livable=True,
due_part_key="Example",
**active_row,
db=db_session,
)
created_list.append(created_managment_room)
created_flat = BuildParts.find_or_create(
address_gov_code="123123123124",
build_id=created_build.id,
build_uu_id=str(created_build.uu_id),
part_code="MF001",
part_net_size=100,
part_no=1,
part_level=1,
part_type_id=build_type_flat.id,
part_type_uu_id=str(build_type_flat.uu_id),
part_direction_id=enum_dropdown.id,
part_direction_uu_id=str(enum_dropdown.uu_id),
human_livable=True,
due_part_key="Example",
**active_row,
db=db_session,
)
created_list.append(created_flat)
build_manager_people = People.find_or_create(
**{
"person_tag": "Build Manager Example",
"firstname": "Example Build Manager",
"surname": "Example",
"sex_code": "M",
"middle_name": "",
"father_name": "Father",
"mother_name": "Mother",
"country_code": "TR",
"national_identity_id": "12312312315",
"birth_place": "Ankara",
"birth_date": "01.07.1990",
"tax_no": "1231231234",
},
db=db_session,
)
created_list.append(build_manager_people)
owner_people = People.find_or_create(
**{
"person_tag": "Owner Example",
"firstname": "Example Owner",
"surname": "Example",
"sex_code": "M",
"middle_name": "",
"father_name": "Father",
"mother_name": "Mother",
"country_code": "TR",
"national_identity_id": "12312312316",
"birth_place": "Ankara",
"birth_date": "01.07.1990",
"tax_no": "1231231234",
},
db=db_session,
)
created_list.append(owner_people)
tenant_people = People.find_or_create(
**{
"person_tag": "Tenant Example",
"firstname": "Example Tenant",
"surname": "Example",
"sex_code": "M",
"middle_name": "",
"father_name": "Father",
"mother_name": "Mother",
"country_code": "TR",
"national_identity_id": "12312312317",
"birth_place": "Ankara",
"birth_date": "01.07.1990",
"tax_no": "1231231234",
},
db=db_session,
)
created_list.append(tenant_people)
main_domain, collection_name = (
"evyos.com.tr",
f"{str(company_management.uu_id)}*Domain",
)
user_build_manager = Users.find_or_create(
person_id=build_manager_people.id,
person_uu_id=str(build_manager_people.uu_id),
user_tag=build_manager_people.person_tag,
email="example.build.manager@gmail.com",
phone_number="+901111111111",
avatar="https://s.tmimgcdn.com/scr/800x500/276800/building-home-nature-logo-vector-template-3_276851-original.jpg",
related_company=str(company_management.uu_id),
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
db=db_session,
)
created_list.append(user_build_manager)
user_build_manager.password_expiry_begins = str(arrow.now())
user_build_manager.password_token = PasswordModule.generate_refresher_token()
user_owner = Users.find_or_create(
person_id=owner_people.id,
person_uu_id=str(owner_people.uu_id),
user_tag=owner_people.person_tag,
email="example.owner@gmail.com",
phone_number="+901111111111",
avatar="https://s.tmimgcdn.com/scr/800x500/276800/building-home-nature-logo-vector-template-3_276851-original.jpg",
related_company=str(company_management.uu_id),
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
db=db_session,
)
created_list.append(user_owner)
user_owner.password_expiry_begins = str(arrow.now())
user_owner.password_token = PasswordModule.generate_refresher_token()
user_tenant = Users.find_or_create(
person_id=tenant_people.id,
person_uu_id=str(tenant_people.uu_id),
user_tag=tenant_people.person_tag,
email="example.tenant@gmail.com",
phone_number="+901111111111",
avatar="https://s.tmimgcdn.com/scr/800x500/276800/building-home-nature-logo-vector-template-3_276851-original.jpg",
related_company=str(company_management.uu_id),
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
db=db_session,
)
created_list.append(user_tenant)
user_tenant.password_expiry_begins = str(arrow.now())
user_tenant.password_token = PasswordModule.generate_refresher_token()
with mongo_handler.collection(collection_name) as mongo_engine:
mongo_engine.insert_one(
document={
"user_uu_id": str(user_build_manager.uu_id),
"other_domains_list": [main_domain],
"main_domain": main_domain,
"modified_at": arrow.now().timestamp(),
}
)
with mongo_handler.collection(collection_name) as mongo_engine:
mongo_engine.insert_one(
document={
"user_uu_id": str(user_owner.uu_id),
"other_domains_list": [main_domain],
"main_domain": main_domain,
"modified_at": arrow.now().timestamp(),
}
)
with mongo_handler.collection(collection_name) as mongo_engine:
mongo_engine.insert_one(
document={
"user_uu_id": str(user_tenant.uu_id),
"other_domains_list": [main_domain],
"main_domain": main_domain,
"modified_at": arrow.now().timestamp(),
}
)
created_build_living_space_prs = BuildLivingSpace.find_or_create(
build_id=created_build.id,
build_uu_id=str(created_build.uu_id),
build_parts_id=created_managment_room.id,
build_parts_uu_id=str(created_managment_room.uu_id),
person_id=build_manager_people.id,
person_uu_id=str(build_manager_people.uu_id),
occupant_type_id=occupant_type_prs.id,
occupant_type_uu_id=str(occupant_type_prs.uu_id),
**active_row,
db=db_session,
)
created_list.append(created_build_living_space_prs)
created_build_living_space_owner = BuildLivingSpace.find_or_create(
build_id=created_build.id,
build_uu_id=str(created_build.uu_id),
build_parts_id=created_flat.id,
build_parts_uu_id=str(created_flat.uu_id),
person_id=owner_people.id,
person_uu_id=str(owner_people.uu_id),
occupant_type_id=occupant_type_owner.id,
occupant_type_uu_id=str(occupant_type_owner.uu_id),
**active_row,
db=db_session,
)
created_list.append(created_build_living_space_owner)
created_build_living_space_tenant = BuildLivingSpace.find_or_create(
build_id=created_build.id,
build_uu_id=str(created_build.uu_id),
build_parts_id=created_flat.id,
build_parts_uu_id=str(created_flat.uu_id),
person_id=tenant_people.id,
person_uu_id=str(tenant_people.uu_id),
occupant_type_id=occupant_type_tenant.id,
occupant_type_uu_id=str(occupant_type_tenant.uu_id),
**active_row,
db=db_session,
)
created_list.append(created_build_living_space_tenant)
db_session.commit()
print("Occupant Defaults Create is now completed")