add: order paths & mds
This commit is contained in:
@@ -45,16 +45,24 @@ def create_all():
|
||||
with engine.begin() as conn:
|
||||
Base.metadata.create_all(bind=conn)
|
||||
|
||||
def run_scripts():
|
||||
from db.models import table_models
|
||||
with get_db() as session:
|
||||
for model in table_models:
|
||||
if hasattr(model, "__scripts__"):
|
||||
scripts = model.__scripts__
|
||||
for script in scripts:
|
||||
session.execute(script)
|
||||
session.commit()
|
||||
|
||||
def init_payload():
|
||||
|
||||
from db.models import table_models
|
||||
with get_db() as session:
|
||||
session.execute(text("SET FOREIGN_KEY_CHECKS = 0;"))
|
||||
for model in table_models:
|
||||
print(f"MODEL -- {model}, {hasattr(model, '__pay_load__')}")
|
||||
if hasattr(model, "__pay_load__"):
|
||||
payload =model.__pay_load__[ENVIRONMENT]
|
||||
payload = model.__pay_load__[ENVIRONMENT]
|
||||
print(f"- - [ - ] hasattr, {ENVIRONMENT} - {payload}")
|
||||
stmt = insert(model.__table__).values(payload).prefix_with("IGNORE")
|
||||
print(f"- - [ - ] {stmt}\n")
|
||||
@@ -74,6 +82,8 @@ def setup_db():
|
||||
print("[ x ] db cleared")
|
||||
create_all()
|
||||
print("[ x ] db created")
|
||||
run_scripts()
|
||||
print("[ x ] db scripts executed")
|
||||
init_payload()
|
||||
print("[ x ] payload loaded")
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#db/models/Markdown.py
|
||||
from sqlalchemy import Column, Text, Integer, String, DateTime, ForeignKey
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import Column, Text, Integer, String, DateTime, ForeignKey, Float, text
|
||||
from db.models import Base
|
||||
import datetime
|
||||
|
||||
@@ -10,6 +11,7 @@ class Markdown(Base):
|
||||
content = Column(Text, nullable=False)
|
||||
created_at = Column(DateTime, default=datetime.datetime.utcnow)
|
||||
path_id = Column(Integer, ForeignKey('path.id'), nullable=False)
|
||||
order = Column(String(36), default=lambda: str(uuid.uuid4()))
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
@@ -18,6 +20,7 @@ class Markdown(Base):
|
||||
'content': self.content,
|
||||
'created_at': self.created_at,
|
||||
'path_id': self.path_id,
|
||||
'order': self.order,
|
||||
}
|
||||
__pay_load__ = {
|
||||
'dev': [
|
||||
@@ -26,4 +29,4 @@ class Markdown(Base):
|
||||
'prod': [
|
||||
{'id': 1, 'title': 'index', 'content': ' ', 'created_at': datetime.datetime.utcnow, 'path_id': 1},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#db/models/Path.py
|
||||
from sqlalchemy import Column, String, Integer, ForeignKey, UniqueConstraint
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import Column, String, Integer, ForeignKey, UniqueConstraint, text
|
||||
from db.models import Base
|
||||
|
||||
|
||||
@@ -8,12 +9,14 @@ class Path(Base):
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
name = Column(String(50), nullable=False)
|
||||
parent_id = Column(Integer, ForeignKey("path.id"), nullable=True)
|
||||
order = Column(String(36), default=lambda: str(uuid.uuid4()))
|
||||
__table_args__ = (UniqueConstraint("parent_id", "name", name="unique_parent_id_name"), )
|
||||
def to_dict(self):
|
||||
return {
|
||||
"id": self.id,
|
||||
"name": self.name,
|
||||
"parent_id": self.parent_id,
|
||||
"order": self.order,
|
||||
}
|
||||
|
||||
__pay_load__ = {
|
||||
@@ -25,4 +28,6 @@ class Path(Base):
|
||||
'prod': [
|
||||
{'id': 1, 'name': '', 'parent_id': None},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user