change schema back to use BIT(1) for boolean
This commit is contained in:
@@ -25,8 +25,8 @@ def get_file_details(mediafile: MediaFile) -> MediaFileResponse | None:
|
|||||||
url=str(mediafile.url),
|
url=str(mediafile.url),
|
||||||
review=(mediafile.review == 1),
|
review=(mediafile.review == 1),
|
||||||
should_download=(mediafile.should_download == 1))
|
should_download=(mediafile.should_download == 1))
|
||||||
print(f"id: {mediafile.id}: review: {response.review} <- {mediafile.review}")
|
#print(f"id: {mediafile.id}: review: {response.review} <- {mediafile.review}")
|
||||||
print(f"id: {mediafile.id}: download: {response.should_download} <- {mediafile.should_download}")
|
#print(f"id: {mediafile.id}: download: {response.should_download} <- {mediafile.should_download}")
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def set_file(model: MediaFileResponse, mediafile: MediaFile) -> None:
|
def set_file(model: MediaFileResponse, mediafile: MediaFile) -> None:
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
from .admin import User, Token, Role, AuthorizationMatrix, ModuleData, MailAccount, Mail
|
||||||
|
from .bookshelf import Article, Book, Author, BookshelfPublisher, ArticleAuthor, BookAuthor
|
||||||
|
from .comic import Comic, Artist, Publisher, Issue, StoryArc, TradePaperback, Volume, ComicWork, WorkType
|
||||||
|
from .metadata import MetaDataTable, MetaDataColumn
|
||||||
|
from .tysc import Card, CardSet, Sport, Team, FieldPosition, Rooster, Player, Vendor
|
||||||
|
from .media import MediaFile, MediaArticle, MediaVideo
|
||||||
|
from .base import Base
|
||||||
|
from .database import KontorDB, ColumnEntry
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from sqlalchemy import Column, ForeignKey, Integer, String, Boolean
|
from sqlalchemy import Column, ForeignKey, Integer, String
|
||||||
|
from sqlalchemy.dialects.mysql import BIT
|
||||||
from sqlalchemy.orm import relationship, mapped_column, Mapped
|
from sqlalchemy.orm import relationship, mapped_column, Mapped
|
||||||
|
|
||||||
from .base import Base, BaseMixin
|
from .base import Base, BaseMixin
|
||||||
@@ -13,7 +14,7 @@ class User(Base, BaseMixin):
|
|||||||
user_name = Column(String(255), nullable=False)
|
user_name = Column(String(255), nullable=False)
|
||||||
email = Column(String(255))
|
email = Column(String(255))
|
||||||
password = Column(String(255))
|
password = Column(String(255))
|
||||||
enabled = Column(Boolean)
|
enabled = Column(BIT(1))
|
||||||
matrix = relationship("AuthorizationMatrix")
|
matrix = relationship("AuthorizationMatrix")
|
||||||
tokens = relationship("Token")
|
tokens = relationship("Token")
|
||||||
|
|
||||||
@@ -33,7 +34,7 @@ class Token(Base, BaseMixin):
|
|||||||
token = Column(String(255), nullable=False, unique=True)
|
token = Column(String(255), nullable=False, unique=True)
|
||||||
name = Column(String(255))
|
name = Column(String(255))
|
||||||
last_used_date: Mapped[datetime] = mapped_column()
|
last_used_date: Mapped[datetime] = mapped_column()
|
||||||
enabled = Column(Boolean)
|
enabled = Column(BIT(1))
|
||||||
user_id = Column(String(255), ForeignKey("user.id"), nullable=False)
|
user_id = Column(String(255), ForeignKey("user.id"), nullable=False)
|
||||||
user = relationship("User", back_populates="tokens")
|
user = relationship("User", back_populates="tokens")
|
||||||
|
|
||||||
@@ -55,7 +56,7 @@ class AuthorizationMatrix(Base, BaseMixin):
|
|||||||
class ModuleData(Base, BaseMixin):
|
class ModuleData(Base, BaseMixin):
|
||||||
__tablename__ = "module_data"
|
__tablename__ = "module_data"
|
||||||
module_name = Column(String(255), nullable=False)
|
module_name = Column(String(255), nullable=False)
|
||||||
import_data = Column(Boolean)
|
import_data = Column(BIT(1))
|
||||||
|
|
||||||
|
|
||||||
class MailAccount(Base, BaseMixin):
|
class MailAccount(Base, BaseMixin):
|
||||||
@@ -65,7 +66,7 @@ class MailAccount(Base, BaseMixin):
|
|||||||
protocol = Column(String(255))
|
protocol = Column(String(255))
|
||||||
user_name = Column(String(255))
|
user_name = Column(String(255))
|
||||||
password = Column(String(255))
|
password = Column(String(255))
|
||||||
start_tls = Column(Boolean)
|
start_tls = Column(BIT(1))
|
||||||
|
|
||||||
|
|
||||||
class Mail(Base, BaseMixin):
|
class Mail(Base, BaseMixin):
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from sqlalchemy import func, Column, String, Boolean
|
from sqlalchemy import func, Column, String
|
||||||
|
from sqlalchemy.dialects.mysql import BIT
|
||||||
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
||||||
|
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ class BaseVideoMixin:
|
|||||||
cloud_link = Column(String(255))
|
cloud_link = Column(String(255))
|
||||||
file_name = Column(String(255))
|
file_name = Column(String(255))
|
||||||
path = Column(String(255))
|
path = Column(String(255))
|
||||||
review = Column(Boolean)
|
review = Column(BIT(1))
|
||||||
title = Column(String(255))
|
title = Column(String(255))
|
||||||
url = Column(String(255), unique=True)
|
url = Column(String(255), unique=True)
|
||||||
should_download = Column(Boolean)
|
should_download = Column(BIT(1))
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from sqlalchemy import Column, ForeignKey, Integer, String, Boolean
|
from sqlalchemy import Column, ForeignKey, Integer, String
|
||||||
|
from sqlalchemy.dialects.mysql import BIT
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
from .base import Base, BaseMixin
|
from .base import Base, BaseMixin
|
||||||
@@ -21,8 +22,8 @@ class Comic(Base, BaseMixin):
|
|||||||
title = Column(String(length=255), unique=True)
|
title = Column(String(length=255), unique=True)
|
||||||
publisher_id = Column(String, ForeignKey('publisher.id'), nullable=False)
|
publisher_id = Column(String, ForeignKey('publisher.id'), nullable=False)
|
||||||
publisher = relationship("Publisher", back_populates="comics")
|
publisher = relationship("Publisher", back_populates="comics")
|
||||||
current_order = Column(Boolean)
|
current_order = Column(BIT(1))
|
||||||
completed = Column(Boolean)
|
completed = Column(BIT(1))
|
||||||
issues = relationship("Issue")
|
issues = relationship("Issue")
|
||||||
story_arcs = relationship("StoryArc")
|
story_arcs = relationship("StoryArc")
|
||||||
trade_paperbacks = relationship("TradePaperback")
|
trade_paperbacks = relationship("TradePaperback")
|
||||||
@@ -63,8 +64,8 @@ class StoryArc(Base, BaseMixin):
|
|||||||
class Issue(Base, BaseMixin):
|
class Issue(Base, BaseMixin):
|
||||||
__tablename__ = "issue"
|
__tablename__ = "issue"
|
||||||
issue_number = Column(String(255))
|
issue_number = Column(String(255))
|
||||||
in_stock = Column(Boolean)
|
in_stock = Column(BIT(1))
|
||||||
is_read = Column(Boolean)
|
is_read = Column(BIT(1))
|
||||||
comic_id = Column(String, ForeignKey("comic.id"), nullable=False)
|
comic_id = Column(String, ForeignKey("comic.id"), nullable=False)
|
||||||
comic = relationship("Comic", back_populates="issues")
|
comic = relationship("Comic", back_populates="issues")
|
||||||
volume_id = Column(String, ForeignKey("volume.id"), nullable=True)
|
volume_id = Column(String, ForeignKey("volume.id"), nullable=True)
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ from datetime import datetime
|
|||||||
from enum import Enum, auto
|
from enum import Enum, auto
|
||||||
from logging import Logger
|
from logging import Logger
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from sqlalchemy import Engine, select
|
from sqlalchemy import select
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
|
||||||
@@ -34,7 +35,6 @@ class StatusType(Enum):
|
|||||||
CLOUD_LINK = auto()
|
CLOUD_LINK = auto()
|
||||||
CLOUD_LINK_ID = auto()
|
CLOUD_LINK_ID = auto()
|
||||||
|
|
||||||
|
|
||||||
class ExportType(Enum):
|
class ExportType(Enum):
|
||||||
JSON = "JSON"
|
JSON = "JSON"
|
||||||
YAML = "YAML"
|
YAML = "YAML"
|
||||||
@@ -43,7 +43,7 @@ class ExportType(Enum):
|
|||||||
|
|
||||||
class KontorDB:
|
class KontorDB:
|
||||||
|
|
||||||
def __init__(self, db_engine: Engine, log: Logger):
|
def __init__(self, db_engine: Any, log: Logger):
|
||||||
self.engine = db_engine
|
self.engine = db_engine
|
||||||
self.registry = {}
|
self.registry = {}
|
||||||
self.init_registry()
|
self.init_registry()
|
||||||
@@ -131,6 +131,7 @@ class KontorDB:
|
|||||||
|
|
||||||
def get_columns(self, table_name: str) -> dict:
|
def get_columns(self, table_name: str) -> dict:
|
||||||
columns = {}
|
columns = {}
|
||||||
|
order = 0
|
||||||
__session__ = sessionmaker(self.engine)
|
__session__ = sessionmaker(self.engine)
|
||||||
table_info = self.get_table_by_name(table_name)
|
table_info = self.get_table_by_name(table_name)
|
||||||
_filters = {'table_id': table_info['id']}
|
_filters = {'table_id': table_info['id']}
|
||||||
@@ -182,7 +183,7 @@ class KontorDB:
|
|||||||
# self.log.info("data: %s", data)
|
# self.log.info("data: %s", data)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def export_db(self, export_type: ExportType, export_file_name: str) -> dict:
|
def export_db(self, export_type: str, export_file_name: str) -> dict:
|
||||||
results = {}
|
results = {}
|
||||||
db = {}
|
db = {}
|
||||||
export_table_list = self.get_table_names()
|
export_table_list = self.get_table_names()
|
||||||
@@ -216,14 +217,14 @@ class KontorDB:
|
|||||||
db[table] = entries
|
db[table] = entries
|
||||||
results[table] = len(entries)
|
results[table] = len(entries)
|
||||||
match export_type:
|
match export_type:
|
||||||
case ExportType.JSON:
|
case "JSON":
|
||||||
json_dump = json.dumps(db, indent=4)
|
json_dump = json.dumps(db, indent=4)
|
||||||
with open(export_file_name, "w") as dump_file:
|
with open(export_file_name, "w") as dump_file:
|
||||||
dump_file.write(json_dump)
|
dump_file.write(json_dump)
|
||||||
case ExportType.YAML:
|
case "YAML":
|
||||||
pass
|
export_file = Path(export_file_name)
|
||||||
case ExportType.SQLITE:
|
case "SQLite":
|
||||||
pass
|
export_file = Path(export_file_name)
|
||||||
self.log.info(f"{len(results)} tables exported")
|
self.log.info(f"{len(results)} tables exported")
|
||||||
return results
|
return results
|
||||||
|
|
||||||
@@ -278,7 +279,7 @@ class KontorDB:
|
|||||||
except IntegrityError as error:
|
except IntegrityError as error:
|
||||||
self.log.info(f"Could not add item, due to: {error.detail}")
|
self.log.info(f"Could not add item, due to: {error.detail}")
|
||||||
if len(existing_ids) > 0:
|
if len(existing_ids) > 0:
|
||||||
print(f"remaining items: {existing_ids}")
|
print(f"remaining items for {table_name}: {existing_ids}")
|
||||||
remaining.extend(existing_ids)
|
remaining.extend(existing_ids)
|
||||||
result['updated'] = updated
|
result['updated'] = updated
|
||||||
result['added'] = added
|
result['added'] = added
|
||||||
@@ -334,13 +335,8 @@ class KontorDB:
|
|||||||
media_file.last_modified_date = datetime.now()
|
media_file.last_modified_date = datetime.now()
|
||||||
media_file.version = 0
|
media_file.version = 0
|
||||||
media_file.url = link
|
media_file.url = link
|
||||||
<<<<<<< HEAD
|
|
||||||
media_file.review = 1
|
media_file.review = 1
|
||||||
media_file.should_download = 1
|
media_file.should_download = 1
|
||||||
=======
|
|
||||||
media_file.review = True
|
|
||||||
media_file.should_download = True
|
|
||||||
>>>>>>> d9d178f (add schema from kontor-schema)
|
|
||||||
try:
|
try:
|
||||||
session.add(media_file)
|
session.add(media_file)
|
||||||
session.commit()
|
session.commit()
|
||||||
@@ -356,6 +352,7 @@ class KontorDB:
|
|||||||
_filter = { 'review': True}
|
_filter = { 'review': True}
|
||||||
with __session__() as session:
|
with __session__() as session:
|
||||||
links = session.query(MediaFile).filter_by(**_filter).all()
|
links = session.query(MediaFile).filter_by(**_filter).all()
|
||||||
|
self.log.info("%d entries found for updating titles", len(links))
|
||||||
for link in links:
|
for link in links:
|
||||||
url = link.url
|
url = link.url
|
||||||
if url is None:
|
if url is None:
|
||||||
@@ -365,7 +362,7 @@ class KontorDB:
|
|||||||
update_list[link.id] = link.title
|
update_list[link.id] = link.title
|
||||||
return update_list
|
return update_list
|
||||||
|
|
||||||
def get_download_list(self) -> list:
|
def get_download_list(self) -> list[uuid.UUID]:
|
||||||
download_list = []
|
download_list = []
|
||||||
__session__ = sessionmaker(self.engine)
|
__session__ = sessionmaker(self.engine)
|
||||||
_filter = { 'should_download': True}
|
_filter = { 'should_download': True}
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ from pathlib import Path
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from sqlalchemy import Column, String, ForeignKey, Boolean
|
from sqlalchemy import Column, String, ForeignKey
|
||||||
|
from sqlalchemy.dialects.mysql import BIT
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
from .base import Base, BaseMixin, BaseVideoMixin
|
from .base import Base, BaseMixin, BaseVideoMixin
|
||||||
@@ -43,12 +44,12 @@ class MediaFile(Base, BaseMixin, BaseVideoMixin):
|
|||||||
lines_list = output.splitlines()
|
lines_list = output.splitlines()
|
||||||
file_name = self.__parse_output__(lines_list)
|
file_name = self.__parse_output__(lines_list)
|
||||||
if file_name is None:
|
if file_name is None:
|
||||||
self.review = True
|
self.review = 1
|
||||||
self.should_download = True
|
self.should_download = 1
|
||||||
self.file_name = None
|
self.file_name = None
|
||||||
else:
|
else:
|
||||||
download_file = Path(file_name)
|
download_file = Path(file_name)
|
||||||
self.should_download = False
|
self.should_download = 0
|
||||||
self.file_name = download_file.name
|
self.file_name = download_file.name
|
||||||
self.cloud_link = str(download_file.absolute())
|
self.cloud_link = str(download_file.absolute())
|
||||||
self.last_modified_date = datetime.now()
|
self.last_modified_date = datetime.now()
|
||||||
@@ -77,16 +78,23 @@ class MediaActorFile(Base, BaseMixin):
|
|||||||
__tablename__ = 'media_actor_file'
|
__tablename__ = 'media_actor_file'
|
||||||
media_actor_id = Column(String(255), ForeignKey("media_actor.id"), nullable=False)
|
media_actor_id = Column(String(255), ForeignKey("media_actor.id"), nullable=False)
|
||||||
media_actor = relationship("MediaActor", back_populates="media_actor_files")
|
media_actor = relationship("MediaActor", back_populates="media_actor_files")
|
||||||
media_file_id = Column(String(255), ForeignKey("media_file.id"), nullable=False)
|
media_file_id = Column(String(255), ForeignKey("media_file.id"), nullable=True)
|
||||||
media_file = relationship("MediaFile", back_populates="media_actor_files")
|
media_file = relationship("MediaFile", back_populates="media_actor_files")
|
||||||
|
|
||||||
|
|
||||||
class MediaArticle(Base, BaseMixin):
|
class MediaArticle(Base, BaseMixin):
|
||||||
__tablename__ = 'media_article'
|
__tablename__ = 'media_article'
|
||||||
review = Column(Boolean)
|
review = Column(BIT(1))
|
||||||
title = Column(String(255))
|
title = Column(String(255))
|
||||||
url = Column(String(255), unique=True)
|
url = Column(String(255), unique=True)
|
||||||
|
|
||||||
|
|
||||||
class MediaVideo(Base, BaseMixin, BaseVideoMixin):
|
class MediaVideo(Base, BaseMixin):
|
||||||
__tablename__ = 'media_video'
|
__tablename__ = 'media_video'
|
||||||
|
cloud_link = Column(String(255))
|
||||||
|
file_name = Column(String(255))
|
||||||
|
path = Column(String(255))
|
||||||
|
review = Column(BIT(1))
|
||||||
|
title = Column(String(255))
|
||||||
|
url = Column(String(255), unique=True)
|
||||||
|
should_download = Column(BIT(1))
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from sqlalchemy import Column, String, ForeignKey, Integer, Boolean
|
from sqlalchemy import Column, String, ForeignKey, Integer
|
||||||
|
from sqlalchemy.dialects.mysql import BIT
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
from .base import Base, BaseMixin
|
from .base import Base, BaseMixin
|
||||||
@@ -27,8 +28,8 @@ class MetaDataColumn(Base, BaseMixin):
|
|||||||
table = relationship("MetaDataTable", back_populates="table_columns")
|
table = relationship("MetaDataTable", back_populates="table_columns")
|
||||||
column_label = Column(String(255))
|
column_label = Column(String(255))
|
||||||
filter_label = Column(String(255))
|
filter_label = Column(String(255))
|
||||||
is_shown = Column(Boolean)
|
is_shown = Column(BIT(1))
|
||||||
show_filter = Column(Boolean)
|
show_filter = Column(BIT(1))
|
||||||
ref_column = Column(String, nullable=True)
|
ref_column = Column(String, nullable=True)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from sqlalchemy import Column, Integer, String, ForeignKey, UniqueConstraint, Boolean
|
from sqlalchemy import Column, Integer, String, ForeignKey, UniqueConstraint
|
||||||
|
from sqlalchemy.dialects.mysql import BIT
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
from .base import Base, BaseMixin
|
from .base import Base, BaseMixin
|
||||||
@@ -77,8 +78,8 @@ class CardSet(Base, BaseMixin):
|
|||||||
UniqueConstraint("name", "vendor_id"),
|
UniqueConstraint("name", "vendor_id"),
|
||||||
)
|
)
|
||||||
name = Column(String(255), index=True)
|
name = Column(String(255), index=True)
|
||||||
parallel_set = Column(Boolean)
|
parallel_set = Column(BIT(1))
|
||||||
insert_set = Column(Boolean)
|
insert_set = Column(BIT(1))
|
||||||
vendor_id = Column(String, ForeignKey("vendor.id"), nullable=False, index=True)
|
vendor_id = Column(String, ForeignKey("vendor.id"), nullable=False, index=True)
|
||||||
vendor = relationship("Vendor", back_populates="card_sets")
|
vendor = relationship("Vendor", back_populates="card_sets")
|
||||||
cards = relationship("Card")
|
cards = relationship("Card")
|
||||||
|
|||||||
Reference in New Issue
Block a user