add metagoups & search on metagroup_id
This commit is contained in:
@@ -7,7 +7,7 @@ if os.getenv("POSTGRES_HOST"):
|
|||||||
echo=False, future=True)
|
echo=False, future=True)
|
||||||
else:
|
else:
|
||||||
sqlite_file_name = os.getenv("SQLITE_DB_PATH", "eveal.db")
|
sqlite_file_name = os.getenv("SQLITE_DB_PATH", "eveal.db")
|
||||||
engine = create_engine(f"sqlite:///{sqlite_file_name}", echo=False, future=True, connect_args={"check_same_thread": False})
|
engine = create_engine(f"sqlite:///{sqlite_file_name}", echo=True, future=True, connect_args={"check_same_thread": False})
|
||||||
|
|
||||||
def get_session():
|
def get_session():
|
||||||
db = Session(engine)
|
db = Session(engine)
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ async def sde_types(sde_type: int | str, db: Session = Depends(get_session)) ->
|
|||||||
|
|
||||||
|
|
||||||
@app.post("/sde/types/search")
|
@app.post("/sde/types/search")
|
||||||
async def sde_types_search(query: List[Dict[Literal["id", "name", "name_i", "marketgroup_id"], int | str]], db: Session = Depends(get_session)) -> List[models_sde.SDEType]:
|
async def sde_types_search(query: List[Dict[Literal["id", "name", "name_i", "marketgroup_id", "metagroup_id"], int | str]], db: Session = Depends(get_session)) -> List[models_sde.SDEType]:
|
||||||
items = []
|
items = []
|
||||||
for q in query:
|
for q in query:
|
||||||
for k in q.keys():
|
for k in q.keys():
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class SDEIcon(SQLModel, table=True):
|
|||||||
groups: List['SDEGroup'] = DynamicRelationship(back_populates="icon")
|
groups: List['SDEGroup'] = DynamicRelationship(back_populates="icon")
|
||||||
marketgroups: List['SDEMarketGroup'] = DynamicRelationship(back_populates="icon")
|
marketgroups: List['SDEMarketGroup'] = DynamicRelationship(back_populates="icon")
|
||||||
types: List['SDEType'] = DynamicRelationship(back_populates="icon")
|
types: List['SDEType'] = DynamicRelationship(back_populates="icon")
|
||||||
|
metagroups: List['SDEMetaGroup'] = DynamicRelationship(back_populates="icon")
|
||||||
|
|
||||||
|
|
||||||
class SDECategory(SQLModel, table=True):
|
class SDECategory(SQLModel, table=True):
|
||||||
@@ -69,6 +70,18 @@ class SDEMarketGroup(SQLModel, table=True):
|
|||||||
types: List['SDEType'] = DynamicRelationship(back_populates="marketgroup")
|
types: List['SDEType'] = DynamicRelationship(back_populates="marketgroup")
|
||||||
|
|
||||||
|
|
||||||
|
class SDEMetaGroup(SQLModel, table=True):
|
||||||
|
id: int = Field(primary_key=True)
|
||||||
|
|
||||||
|
name: str
|
||||||
|
iconSuffix: Optional[str] = None
|
||||||
|
|
||||||
|
icon_id: Optional[int] = Field(default=None, foreign_key="sdeicon.id")
|
||||||
|
icon: Optional[SDEIcon] = Relationship(back_populates="metagroups")
|
||||||
|
|
||||||
|
types: List['SDEType'] = DynamicRelationship(back_populates="metagroup")
|
||||||
|
|
||||||
|
|
||||||
class SDEType(SQLModel, table=True):
|
class SDEType(SQLModel, table=True):
|
||||||
id: int = Field(primary_key=True)
|
id: int = Field(primary_key=True)
|
||||||
|
|
||||||
@@ -78,6 +91,9 @@ class SDEType(SQLModel, table=True):
|
|||||||
marketgroup_id: Optional[int] = Field(default=None, foreign_key="sdemarketgroup.id")
|
marketgroup_id: Optional[int] = Field(default=None, foreign_key="sdemarketgroup.id")
|
||||||
marketgroup: Optional[SDEMarketGroup] = Relationship(back_populates="types")
|
marketgroup: Optional[SDEMarketGroup] = Relationship(back_populates="types")
|
||||||
|
|
||||||
|
metagroup_id: Optional[int] = Field(default=None, foreign_key="sdemetagroup.id")
|
||||||
|
metagroup: Optional[SDEMetaGroup] = Relationship(back_populates="types")
|
||||||
|
|
||||||
name: str
|
name: str
|
||||||
published: bool = False
|
published: bool = False
|
||||||
description: Optional[str] = None
|
description: Optional[str] = None
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from eveal.database import engine
|
|||||||
from sqlmodel import Session, SQLModel, select
|
from sqlmodel import Session, SQLModel, select
|
||||||
from eveal import models_sde
|
from eveal import models_sde
|
||||||
|
|
||||||
|
SQLModel.metadata.drop_all(engine) # use alembic!
|
||||||
SQLModel.metadata.create_all(engine)
|
SQLModel.metadata.create_all(engine)
|
||||||
|
|
||||||
|
|
||||||
@@ -102,6 +103,25 @@ with Session(engine) as db:
|
|||||||
print(f"Updated {total_marketgroup_links} marketgroup Parents")
|
print(f"Updated {total_marketgroup_links} marketgroup Parents")
|
||||||
|
|
||||||
|
|
||||||
|
print("Importing metagroups...")
|
||||||
|
with open("static_eve/sde/fsd/metaGroups.yaml", "r", encoding="utf-8") as f:
|
||||||
|
metagroups = yaml.safe_load(f)
|
||||||
|
new_metagroups = total_metagroups = 0
|
||||||
|
with Session(engine) as db:
|
||||||
|
for id, metagroup in metagroups.items():
|
||||||
|
db_metagroups = db.get(models_sde.SDEMetaGroup, id)
|
||||||
|
if not db_metagroups:
|
||||||
|
db_metagroups = models_sde.SDEMetaGroup(id=id)
|
||||||
|
db.add(db_metagroups)
|
||||||
|
new_metagroups += 1
|
||||||
|
db_metagroups.name = metagroup['nameID']['en']
|
||||||
|
db_metagroups.iconSuffix = metagroup['iconSuffix'] if 'iconSuffix' in metagroup else None
|
||||||
|
db_metagroups.icon_id = metagroup['iconID'] if 'iconID' in metagroup else None
|
||||||
|
total_metagroups += 1
|
||||||
|
db.commit()
|
||||||
|
print(f"Imported {new_metagroups} metagroups / {total_metagroups} total metagroups.")
|
||||||
|
|
||||||
|
|
||||||
print("Importing types...")
|
print("Importing types...")
|
||||||
with open("static_eve/sde/fsd/typeIDs.yaml", "r", encoding="utf-8") as f:
|
with open("static_eve/sde/fsd/typeIDs.yaml", "r", encoding="utf-8") as f:
|
||||||
types = yaml.safe_load(f)
|
types = yaml.safe_load(f)
|
||||||
@@ -124,6 +144,7 @@ with Session(engine) as db:
|
|||||||
db_type.icon_id = type['iconID'] if 'iconID' in type else None
|
db_type.icon_id = type['iconID'] if 'iconID' in type else None
|
||||||
db_type.portionSize = type['portionSize']
|
db_type.portionSize = type['portionSize']
|
||||||
db_type.volume = type['volume'] if 'volume' in type else None
|
db_type.volume = type['volume'] if 'volume' in type else None
|
||||||
|
db_type.metagroup_id = type['metaGroupID'] if 'metaGroupID' in type else None
|
||||||
total_types += 1
|
total_types += 1
|
||||||
db.commit()
|
db.commit()
|
||||||
print(f"Imported {new_types} types / {total_types} total types.")
|
print(f"Imported {new_types} types / {total_types} total types.")
|
||||||
@@ -136,7 +157,6 @@ new_typemat = total_typemat = 0
|
|||||||
with Session(engine) as db:
|
with Session(engine) as db:
|
||||||
for id, material in materials.items():
|
for id, material in materials.items():
|
||||||
for mat in material['materials']:
|
for mat in material['materials']:
|
||||||
# db_typemat = db.exec(select(models_sde.SDETypeMaterial).where(models_sde.SDETypeMaterial.type_id == id, models_sde.SDETypeMaterial.material_type_id == mat['materialTypeID'])).one_or_none()
|
|
||||||
db_typemat = db.query(models_sde.SDETypeMaterial).filter(models_sde.SDETypeMaterial.type_id == id, models_sde.SDETypeMaterial.material_type_id == mat['materialTypeID']).one_or_none()
|
db_typemat = db.query(models_sde.SDETypeMaterial).filter(models_sde.SDETypeMaterial.type_id == id, models_sde.SDETypeMaterial.material_type_id == mat['materialTypeID']).one_or_none()
|
||||||
if not db_typemat:
|
if not db_typemat:
|
||||||
db_typemat = models_sde.SDETypeMaterial()
|
db_typemat = models_sde.SDETypeMaterial()
|
||||||
|
|||||||
Reference in New Issue
Block a user