improve: change db schema for settings
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import Column, Text, Integer, String, DateTime, ForeignKey, Float, text, UniqueConstraint
|
||||
from sqlalchemy import Column, Text, Integer, String, DateTime, ForeignKey, UniqueConstraint
|
||||
from db.models import Base
|
||||
import datetime
|
||||
|
||||
@@ -13,6 +13,8 @@ class Markdown(Base):
|
||||
path_id = Column(Integer, ForeignKey('path.id'), nullable=False)
|
||||
order = Column(String(36), default=lambda: str(uuid.uuid4()))
|
||||
shortcut = Column(String(36), default="")
|
||||
template_id = Column(Integer, ForeignKey("markdown_template.id"), nullable=True)
|
||||
__table_args__ = (UniqueConstraint('path_id', 'title', name="unique_path_id_title"),)
|
||||
def to_dict(self):
|
||||
return {
|
||||
'id': self.id,
|
||||
@@ -22,6 +24,7 @@ class Markdown(Base):
|
||||
'path_id': self.path_id,
|
||||
'order': self.order,
|
||||
'shortcut': self.shortcut,
|
||||
'template_id': self.template_id,
|
||||
}
|
||||
__payload__ = {
|
||||
'dev': [
|
||||
|
||||
15
db/models/MarkdownSetting.py
Normal file
15
db/models/MarkdownSetting.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from sqlalchemy import Column, Integer, ForeignKey
|
||||
|
||||
from db.models import Base
|
||||
|
||||
|
||||
class MarkdownSetting(Base):
|
||||
__tablename__ = 'markdown_settings'
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
template_setting_id = Column(Integer, ForeignKey('markdown_template.id'), nullable=True)
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"id": self.id,
|
||||
"template_setting_id": self.template_setting_id,
|
||||
}
|
||||
18
db/models/MarkdownTemplate.py
Normal file
18
db/models/MarkdownTemplate.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from sqlalchemy import Column, Text, Integer, String, UniqueConstraint
|
||||
from db.models import Base
|
||||
|
||||
class MarkdownTemplate(Base):
|
||||
__tablename__ = 'markdown_template'
|
||||
id = Column(Integer, primary_key=True)
|
||||
title = Column(String(255), nullable=False)
|
||||
parameters = Column(Text, nullable=True)
|
||||
define = Column(Text, nullable=True)
|
||||
__table_args__ = (UniqueConstraint("title", name="unique_title"),)
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
'id': self.id,
|
||||
'title': self.title,
|
||||
'parameters': self.parameters,
|
||||
'define': self.define,
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import Column, String, Integer, ForeignKey, UniqueConstraint, text
|
||||
from sqlalchemy import Column, String, Integer, ForeignKey, UniqueConstraint
|
||||
from db.models import Base
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ class Path(Base):
|
||||
name = Column(String(50), nullable=False)
|
||||
parent_id = Column(Integer, ForeignKey("path.id"), nullable=True)
|
||||
order = Column(String(36), default=lambda: str(uuid.uuid4()))
|
||||
setting_id = Column(Integer, ForeignKey("path_settings.id"), nullable=True)
|
||||
__table_args__ = (UniqueConstraint("parent_id", "name", name="unique_parent_id_name"), )
|
||||
def to_dict(self):
|
||||
return {
|
||||
@@ -17,6 +18,7 @@ class Path(Base):
|
||||
"name": self.name,
|
||||
"parent_id": self.parent_id,
|
||||
"order": self.order,
|
||||
"setting_id": self.setting_id
|
||||
}
|
||||
|
||||
__payload__ = {
|
||||
|
||||
17
db/models/PathSetting.py
Normal file
17
db/models/PathSetting.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from sqlalchemy import Column, Integer, ForeignKey
|
||||
|
||||
from db.models import Base
|
||||
|
||||
|
||||
class PathSetting(Base):
|
||||
__tablename__ = 'path_settings'
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
webhook_setting_id = Column(Integer, ForeignKey('webhook_setting.id'), nullable=True)
|
||||
template_setting_id = Column(Integer, ForeignKey('path_template.id'), nullable=True)
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"id": self.id,
|
||||
"webhook_setting_id": self.webhook_setting_id,
|
||||
"template_setting_id": self.template_setting_id,
|
||||
}
|
||||
18
db/models/PathTemplate.py
Normal file
18
db/models/PathTemplate.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from sqlalchemy import Column, Integer, Text, UniqueConstraint, String
|
||||
|
||||
from db.models import Base
|
||||
|
||||
|
||||
class PathTemplate(Base):
|
||||
__tablename__ = 'path_template'
|
||||
id = Column(Integer, primary_key=True)
|
||||
title = Column(String(255), nullable=False)
|
||||
structure = Column(Text, nullable=False)
|
||||
__table_args__ = (UniqueConstraint("title", name="unique_title"),)
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
'id': self.id,
|
||||
'title': self.title,
|
||||
'structure': self.structure
|
||||
}
|
||||
@@ -1,23 +1,19 @@
|
||||
from sqlalchemy import Column, String, Integer, ForeignKey, UniqueConstraint, Boolean
|
||||
from sqlalchemy import Column, Text, Integer, ForeignKey, UniqueConstraint, Boolean
|
||||
from db.models import Base
|
||||
|
||||
|
||||
class WebhookSetting(Base):
|
||||
__tablename__ = 'webhook_setting'
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
path_id = Column(Integer, ForeignKey('path.id'), nullable=False)
|
||||
webhook_id = Column(Integer, ForeignKey('webhook.id'), nullable=False)
|
||||
webhook_id = Column(Integer, ForeignKey('webhook.id'), nullable=True)
|
||||
recursive = Column(Boolean, default=False)
|
||||
additional_header = Column(String(500), nullable=True)
|
||||
additional_header = Column(Text, nullable=True)
|
||||
enabled = Column(Boolean, default=True)
|
||||
on_events = Column(Integer, default=0)
|
||||
|
||||
__table_args__ = (UniqueConstraint('webhook_id', 'path_id', name='_webhook_path_uc'),)
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"id": self.id,
|
||||
"path_id": self.path_id,
|
||||
"webhook_id": self.webhook_id,
|
||||
"recursive": self.recursive,
|
||||
"additional_header": self.additional_header,
|
||||
|
||||
Reference in New Issue
Block a user