add method for import data
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from datetime import datetime
|
||||
from typing import Any, AnyStr, Dict
|
||||
|
||||
from sqlalchemy import Column, ForeignKey, Integer, String, Boolean
|
||||
from sqlalchemy.orm import relationship, mapped_column, Mapped
|
||||
@@ -27,6 +28,18 @@ class Profile(Base, BaseMixin):
|
||||
full_name += self.last_name
|
||||
return full_name
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.first_name = import_data['first_name']
|
||||
self.last_name = import_data['last_name']
|
||||
self.user_name = import_data['user_name']
|
||||
self.email = import_data['email']
|
||||
self.password = import_data['password']
|
||||
self.enabled = import_data['enabled']
|
||||
|
||||
|
||||
class Token(Base, BaseMixin):
|
||||
__tablename__ = "token"
|
||||
@@ -37,12 +50,31 @@ class Token(Base, BaseMixin):
|
||||
profile_id = Column(String, ForeignKey("profile.id"), nullable=False)
|
||||
profile = relationship("Profile", back_populates="tokens")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.token = import_data['token']
|
||||
self.name = import_data['name']
|
||||
self.last_used_date = import_data['last_used_date']
|
||||
self.enabled = import_data['enabled']
|
||||
self.profile_id = import_data['profile_id']
|
||||
self.password = import_data['password']
|
||||
|
||||
|
||||
class Permission(Base, BaseMixin):
|
||||
__tablename__ = "permission"
|
||||
name = Column(String, nullable=False)
|
||||
assignments = relationship("Assignment")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
|
||||
|
||||
class Assignment(Base, BaseMixin):
|
||||
__tablename__ = "assignment"
|
||||
@@ -51,12 +83,28 @@ class Assignment(Base, BaseMixin):
|
||||
permission_id = Column(String, ForeignKey("permission.id"), nullable=False)
|
||||
permission = relationship("Permission", back_populates="assignments")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.profile_id = import_data['profile_id']
|
||||
self.permission_id = import_data['permission_id']
|
||||
|
||||
|
||||
class ModuleData(Base, BaseMixin):
|
||||
__tablename__ = "module_data"
|
||||
module_name = Column(String, nullable=False)
|
||||
import_data = Column(Boolean)
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.module_name = import_data['module_name']
|
||||
self.import_data = import_data['import_data']
|
||||
|
||||
|
||||
class MailAccount(Base, BaseMixin):
|
||||
__tablename__ = "mail_account"
|
||||
@@ -67,6 +115,18 @@ class MailAccount(Base, BaseMixin):
|
||||
password = Column(String)
|
||||
start_tls = Column(Boolean)
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.host = import_data['host']
|
||||
self.port = import_data['port']
|
||||
self.protocol = import_data['protocol']
|
||||
self.user_name = import_data['user_name']
|
||||
self.password = import_data['password']
|
||||
self.start_tls = import_data['start_tls']
|
||||
|
||||
|
||||
class Mail(Base, BaseMixin):
|
||||
__tablename__ = "mail"
|
||||
@@ -75,3 +135,14 @@ class Mail(Base, BaseMixin):
|
||||
body: Mapped[str] = mapped_column()
|
||||
sent_date: Mapped[datetime] = mapped_column()
|
||||
received_date: Mapped[datetime] = mapped_column()
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.folder = import_data['folder']
|
||||
self.subject = import_data['subject']
|
||||
self.body = import_data['body']
|
||||
self.sent_date = import_data['sent_date']
|
||||
self.received_date = import_data['received_date']
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from typing import Any, AnyStr, Dict
|
||||
from sqlalchemy import Column, ForeignKey, Integer, String
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
@@ -9,6 +10,13 @@ class Article(Base, BaseMixin):
|
||||
title = Column(String, unique=True)
|
||||
article_authors = relationship("ArticleAuthor")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.title = import_data['title']
|
||||
|
||||
|
||||
class Author(Base, BaseMixin):
|
||||
__tablename__ = 'author'
|
||||
@@ -17,12 +25,27 @@ class Author(Base, BaseMixin):
|
||||
article_authors = relationship("ArticleAuthor")
|
||||
book_authors = relationship("BookAuthor")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.first_name = import_data['first_name']
|
||||
self.last_name = import_data['last_name']
|
||||
|
||||
|
||||
class BookshelfPublisher(Base, BaseMixin):
|
||||
__tablename__ = 'bookshelf_publisher'
|
||||
name = Column(String, unique=True)
|
||||
books = relationship("Book")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
|
||||
|
||||
class Book(Base, BaseMixin):
|
||||
__tablename__ = 'book'
|
||||
@@ -33,6 +56,16 @@ class Book(Base, BaseMixin):
|
||||
publisher = relationship('BookshelfPublisher', back_populates="books")
|
||||
book_authors = relationship("BookAuthor")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.isbn = import_data['isbn']
|
||||
self.title = import_data['title']
|
||||
self.year = import_data['year']
|
||||
self.publisher_id = import_data['publisher_id']
|
||||
|
||||
|
||||
class ArticleAuthor(Base, BaseMixin):
|
||||
__tablename__ = 'article_author'
|
||||
@@ -41,6 +74,14 @@ class ArticleAuthor(Base, BaseMixin):
|
||||
author_id = Column(String, ForeignKey('author.id'), nullable=False)
|
||||
author = relationship('Author', back_populates="article_authors")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.article_id = import_data['article_id']
|
||||
self.author_id = import_data['author_id']
|
||||
|
||||
|
||||
class BookAuthor(Base, BaseMixin):
|
||||
__tablename__ = 'book_author'
|
||||
@@ -48,3 +89,11 @@ class BookAuthor(Base, BaseMixin):
|
||||
author = relationship('Author', back_populates="book_authors")
|
||||
book_id = Column(String, ForeignKey('book.id'), nullable=False)
|
||||
book = relationship('Book', back_populates="book_authors")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.author_id = import_data['author_id']
|
||||
self.book_id = import_data['book_id']
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
from typing import AnyStr, Dict, List, Optional, Any
|
||||
from sqlalchemy import Column, ForeignKey, Integer, String, Boolean, func
|
||||
from sqlalchemy.orm import relationship, Mapped, mapped_column
|
||||
|
||||
@@ -25,6 +25,14 @@ class Publisher(Base):
|
||||
def __str__(self):
|
||||
return self.__repr__()
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
self.parent_publisher_id = import_data['parent_publisher_id']
|
||||
|
||||
|
||||
class Comic(Base, BaseMixin):
|
||||
__tablename__ = 'comic'
|
||||
@@ -46,6 +54,18 @@ class Comic(Base, BaseMixin):
|
||||
def __str__(self):
|
||||
return f'{self.title}({self.id})'
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.title = import_data['title']
|
||||
self.publisher_id = import_data['publisher_id']
|
||||
self.current_order = import_data['current_order']
|
||||
self.completed = import_data['completed']
|
||||
if 'weblink' in import_data:
|
||||
self.weblink = import_data['weblink']
|
||||
|
||||
|
||||
class Volume(Base, BaseMixin):
|
||||
__tablename__ = "volume"
|
||||
@@ -55,6 +75,14 @@ class Volume(Base, BaseMixin):
|
||||
story_arcs = relationship("StoryArc")
|
||||
issues = relationship("Issue")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
self.comic_id = import_data['comic_id']
|
||||
|
||||
|
||||
class TradePaperback(Base, BaseMixin):
|
||||
__tablename__ = "trade_paperback"
|
||||
@@ -64,6 +92,16 @@ class TradePaperback(Base, BaseMixin):
|
||||
comic_id = Column(String, ForeignKey("comic.id"), nullable=False)
|
||||
comic = relationship("Comic", back_populates="trade_paperbacks")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
self.issue_start = import_data['issue_start']
|
||||
self.issue_end = import_data['issue_end']
|
||||
self.comic_id = import_data['comic_id']
|
||||
|
||||
|
||||
class StoryArc(Base, BaseMixin):
|
||||
__tablename__ = "story_arc"
|
||||
@@ -74,6 +112,15 @@ class StoryArc(Base, BaseMixin):
|
||||
volume = relationship("Volume", back_populates="story_arcs")
|
||||
issues = relationship("Issue")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
self.comic_id = import_data['comic_id']
|
||||
self.volume_id = import_data['volume_id']
|
||||
|
||||
|
||||
class Issue(Base, BaseMixin):
|
||||
__tablename__ = "issue"
|
||||
@@ -87,6 +134,18 @@ class Issue(Base, BaseMixin):
|
||||
story_arc_id = Column(String, ForeignKey("story_arc.id"), nullable=True)
|
||||
story_arc = relationship("StoryArc", back_populates="issues")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.issue_number = import_data['issue_number']
|
||||
self.in_stock = import_data['in_stock']
|
||||
self.is_read = import_data['is_read']
|
||||
self.comic_id = import_data['comic_id']
|
||||
self.volume_id = import_data['volume_id']
|
||||
self.story_arc_id = import_data['story_arc_id']
|
||||
|
||||
|
||||
class Artist(Base, BaseMixin):
|
||||
__tablename__ = "artist"
|
||||
@@ -94,6 +153,15 @@ class Artist(Base, BaseMixin):
|
||||
weblink = Column(String, nullable=True)
|
||||
comic_works = relationship("ComicWork")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
if 'weblink' in import_data:
|
||||
self.weblink = import_data['weblink']
|
||||
|
||||
|
||||
class WorkType(Base, BaseMixin):
|
||||
__tablename__ = "worktype"
|
||||
@@ -106,6 +174,13 @@ class WorkType(Base, BaseMixin):
|
||||
def __str__(self):
|
||||
return f'{self.name}({self.id})'
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
|
||||
|
||||
class ComicWork(Base, BaseMixin):
|
||||
__tablename__ = "comic_work"
|
||||
@@ -116,3 +191,11 @@ class ComicWork(Base, BaseMixin):
|
||||
work_type_id = Column(String, ForeignKey("worktype.id"), nullable=False)
|
||||
work_type = relationship("WorkType", back_populates="comic_works")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.comic_id = import_data['comic_id']
|
||||
self.artist_id = import_data['artist_id']
|
||||
self.work_type_id = import_data['work_type_id']
|
||||
|
||||
@@ -2,7 +2,7 @@ import re
|
||||
import subprocess
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from typing import Any, AnyStr, Dict
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from sqlalchemy import Boolean, Column, False_, String, ForeignKey
|
||||
@@ -21,6 +21,19 @@ class MediaFile(Base, BaseMixin, BaseVideoMixin):
|
||||
def __str__(self):
|
||||
return f'{self.title}({self.id})'
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.cloud_link = import_data['cloud_link']
|
||||
self.file_name = import_data['file_name']
|
||||
self.path = import_data['path']
|
||||
self.review = import_data['review']
|
||||
self.title = import_data['title']
|
||||
self.url = import_data['url']
|
||||
self.should_download = import_data['should_download']
|
||||
|
||||
def update_title(self) -> None:
|
||||
print(f"update title for {self.url}")
|
||||
try:
|
||||
@@ -72,6 +85,13 @@ class MediaActor(Base, BaseMixin):
|
||||
name = Column(String)
|
||||
media_actor_files = relationship("MediaActorFile")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
|
||||
|
||||
class MediaActorFile(Base, BaseMixin):
|
||||
__tablename__ = 'media_actor_file'
|
||||
@@ -80,6 +100,15 @@ class MediaActorFile(Base, BaseMixin):
|
||||
media_file_id = Column(String, ForeignKey("media_file.id"), nullable=True)
|
||||
media_file = relationship("MediaFile", back_populates="media_actor_files")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.media_actor_id = import_data['media_actor_id']
|
||||
self.media_file_id = import_data['media_file_id']
|
||||
|
||||
|
||||
|
||||
class MediaArticle(Base, BaseMixin):
|
||||
__tablename__ = 'media_article'
|
||||
@@ -87,6 +116,16 @@ class MediaArticle(Base, BaseMixin):
|
||||
title = Column(String)
|
||||
url = Column(String, unique=True)
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.review = import_data['review']
|
||||
self.title = import_data['title']
|
||||
self.url = import_data['url']
|
||||
|
||||
|
||||
|
||||
class MediaVideo(Base, BaseMixin):
|
||||
__tablename__ = 'media_video'
|
||||
@@ -97,3 +136,16 @@ class MediaVideo(Base, BaseMixin):
|
||||
title = Column(String)
|
||||
url = Column(String, unique=True)
|
||||
should_download = Column(Boolean)
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.cloud_link = import_data['cloud_link']
|
||||
self.file_name = import_data['file_name']
|
||||
self.path = import_data['path']
|
||||
self.review = import_data['review']
|
||||
self.title = import_data['title']
|
||||
self.url = import_data['url']
|
||||
self.should_download = import_data['should_download']
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from typing import Any, AnyStr, Dict
|
||||
from sqlalchemy import Column, String, ForeignKey, Integer, Boolean
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
@@ -15,6 +16,13 @@ class MetaDataTable(Base, BaseMixin):
|
||||
def __str__(self):
|
||||
return f'{self.table_name}({self.id})'
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.table_name = import_data['table_name']
|
||||
|
||||
|
||||
class MetaDataColumn(Base, BaseMixin):
|
||||
__tablename__ = 'meta_data_column'
|
||||
@@ -39,3 +47,20 @@ class MetaDataColumn(Base, BaseMixin):
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.column_name}({self.id})'
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.column_name = import_data['column_name']
|
||||
self.column_sync_name = import_data['column_sync_name']
|
||||
self.column_type = import_data['column_type']
|
||||
self.column_modifier = import_data['column_modifier']
|
||||
self.column_order = import_data['column_order']
|
||||
self.table_id = import_data['table_id']
|
||||
self.column_label = import_data['column_label']
|
||||
self.filter_label = import_data['filter_label']
|
||||
self.is_shown = import_data['is_shown']
|
||||
self.show_filter = import_data['show_filter']
|
||||
self.ref_column = import_data['ref_column']
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from typing import AnyStr, Dict, Any
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, UniqueConstraint, Boolean
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
@@ -13,6 +14,16 @@ class Sport(Base, BaseMixin):
|
||||
teams = relationship("Team")
|
||||
positions = relationship("FieldPosition")
|
||||
|
||||
def __repr__(self):
|
||||
return f"Sport(id={self.id}, name={self.name}, created_date={self.created_date})"
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, AnyStr]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
|
||||
|
||||
class Team(Base, BaseMixin):
|
||||
__tablename__ = "team"
|
||||
@@ -22,6 +33,15 @@ class Team(Base, BaseMixin):
|
||||
sport = relationship("Sport", back_populates="teams")
|
||||
roosters = relationship("Rooster")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, AnyStr]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
self.short_name = import_data['short_name']
|
||||
self.sport_id = import_data['sport_id']
|
||||
|
||||
|
||||
class FieldPosition(Base, BaseMixin):
|
||||
__tablename__ = "field_position"
|
||||
@@ -35,6 +55,15 @@ class FieldPosition(Base, BaseMixin):
|
||||
sport = relationship("Sport", back_populates="positions")
|
||||
roosters = relationship("Rooster")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, AnyStr]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
self.short_name = import_data['short_name']
|
||||
self.sport_id = import_data['sport_id']
|
||||
|
||||
|
||||
class Player(Base, BaseMixin):
|
||||
__tablename__ = "player"
|
||||
@@ -48,6 +77,14 @@ class Player(Base, BaseMixin):
|
||||
def get_full_name(self) -> str:
|
||||
return f"{self.last_name}, {self.first_name}"
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, AnyStr]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.first_name = import_data['first_name']
|
||||
self.last_name = import_data['last_name']
|
||||
|
||||
|
||||
class Rooster(Base, BaseMixin):
|
||||
__tablename__ = "rooster"
|
||||
@@ -63,6 +100,15 @@ class Rooster(Base, BaseMixin):
|
||||
position = relationship("FieldPosition", back_populates="roosters")
|
||||
cards = relationship("Card")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, AnyStr]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.team_id = import_data['team_id']
|
||||
self.player_id = import_data['player_id']
|
||||
self.position_id = import_data['position_id']
|
||||
|
||||
|
||||
class Vendor(Base, BaseMixin):
|
||||
__tablename__ = "vendor"
|
||||
@@ -70,6 +116,13 @@ class Vendor(Base, BaseMixin):
|
||||
card_sets = relationship("CardSet")
|
||||
cards = relationship("Card")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, AnyStr]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
|
||||
|
||||
class CardSet(Base, BaseMixin):
|
||||
__tablename__ = "card_set"
|
||||
@@ -83,6 +136,16 @@ class CardSet(Base, BaseMixin):
|
||||
vendor = relationship("Vendor", back_populates="card_sets")
|
||||
cards = relationship("Card")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, AnyStr]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
self.parallel_set = import_data['parallel_set']
|
||||
self.insert_set = import_data['insert_set']
|
||||
self.vendor_id = import_data['vendor_id']
|
||||
|
||||
|
||||
class Card(Base, BaseMixin):
|
||||
__tablename__ = "card"
|
||||
@@ -97,3 +160,14 @@ class Card(Base, BaseMixin):
|
||||
rooster = relationship("Rooster", back_populates="cards")
|
||||
vendor_id = Column(String, ForeignKey("vendor.id"), nullable=False)
|
||||
vendor = relationship("Vendor", back_populates="cards")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.card_number = import_data['card_number']
|
||||
self.year = import_data['year']
|
||||
self.card_set_id = import_data['card_set_id']
|
||||
self.rooster_id = import_data['rooster_id']
|
||||
self.vendor_id = import_data['vendor_id']
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
import data from json file to MariaDB
|
||||
import data from json file to PostgreSQL
|
||||
"""
|
||||
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
|
||||
|
||||
@@ -11,6 +11,7 @@ from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker, Session
|
||||
from db.models.base import Base
|
||||
from db.models import registry
|
||||
from psycopg2.errors import NotNullViolation
|
||||
from config import get_logger
|
||||
|
||||
parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
|
||||
@@ -62,11 +63,26 @@ def update_item(db: Session, import_data: Dict[AnyStr, Any], item: Any, dry_run:
|
||||
existing_value = getattr(item, str(key))
|
||||
if existing_value != value:
|
||||
if not dry_run:
|
||||
log.info(f"update {key}({existing_value}) with {value}")
|
||||
setattr(model, str(key), value)
|
||||
log.debug(f"update {key}({existing_value}) with {value}")
|
||||
setattr(item, str(key), value)
|
||||
db.add(item)
|
||||
db.commit()
|
||||
|
||||
def item_import(db: Session, import_data: Dict[AnyStr, Any], dry_run: bool, log):
|
||||
log.debug(f"import {import_data}")
|
||||
if not dry_run:
|
||||
log.info(f"model: {repr(model)} {import_data}")
|
||||
try:
|
||||
new_item = model()
|
||||
new_item.import_dict(import_data)
|
||||
log.info(f"new item: {new_item}")
|
||||
db.add(new_item)
|
||||
db.commit()
|
||||
except NotNullViolation as notnull:
|
||||
log.info(f"import failed: {notnull} {import_data}")
|
||||
except Exception as error:
|
||||
log.info(f"import failed: {error}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger = get_logger(args.verbose, "kontor")
|
||||
@@ -78,7 +94,10 @@ if __name__ == '__main__':
|
||||
if args.cleanup:
|
||||
cleanup_database(db, logger, args.dry_run)
|
||||
data = load_data(args.file, logger)
|
||||
for tablename in data:
|
||||
table_list: List = list(data.keys())
|
||||
logger.info(f"Liste der Tabellen: {table_list}")
|
||||
sorted_table_list: List = table_list
|
||||
for tablename in sorted_table_list:
|
||||
model = registry[tablename]
|
||||
existing_items = db.query(model).all()
|
||||
existing_ids = get_ids(existing_items)
|
||||
@@ -92,6 +111,7 @@ if __name__ == '__main__':
|
||||
existing_ids.remove(import_item['id'])
|
||||
else:
|
||||
logger.debug(f"import {import_item['id']}")
|
||||
item_import(db, import_item, args.dry_run, logger)
|
||||
logger.info(f"remaining items for {tablename}: {len(existing_ids)}")
|
||||
logger.info('kontor.import finished')
|
||||
|
||||
|
||||
@@ -179,12 +179,14 @@ public class SetupModuleAdmin implements ApplicationListener<ContextRefreshedEve
|
||||
metaDataService.getColumn(artistTable, "last_modified_date", "modified", "TIMESTAMP", null, 3, Boolean.FALSE, "", Boolean.FALSE, null);
|
||||
metaDataService.getColumn(artistTable, "version", "version", "LONG", null, 4, Boolean.FALSE, "", Boolean.FALSE, null);
|
||||
metaDataService.getColumn(artistTable, "name", "name", "TEXT", "UNIQUE", 5, Boolean.FALSE, "", Boolean.FALSE, null);
|
||||
metaDataService.getColumn(artistTable, "weblink", "weblink", "TEXT", null, 9, Boolean.TRUE, "Link", Boolean.FALSE, null);
|
||||
MetaDataTable publisherTable = metaDataService.getTable("publisher");
|
||||
metaDataService.getColumn(publisherTable, "id", "identifier", "TEXT", "PRIMARY KEY", 1, Boolean.TRUE, "", Boolean.FALSE, null);
|
||||
metaDataService.getColumn(publisherTable, "created_date", "created", "TIMESTAMP", null, 2, Boolean.FALSE, "", Boolean.FALSE, null);
|
||||
metaDataService.getColumn(publisherTable, "last_modified_date", "modified", "TIMESTAMP", null, 3, Boolean.FALSE, "", Boolean.FALSE, null);
|
||||
metaDataService.getColumn(publisherTable, "version", "version", "LONG", null, 4, Boolean.FALSE, "", Boolean.FALSE, null);
|
||||
metaDataService.getColumn(publisherTable, "name", "name", "TEXT", "UNIQUE", 5, Boolean.TRUE, "", Boolean.FALSE, null);
|
||||
metaDataService.getColumn(publisherTable, "parent_publisher_id", "parent_publisher_id", "TEXT", null, 6, Boolean.TRUE, "Parent Company", Boolean.FALSE, null, "name");
|
||||
MetaDataTable comicTable = metaDataService.getTable("comic");
|
||||
metaDataService.getColumn(comicTable, "id", "identifier", "TEXT", "PRIMARY KEY", 1, Boolean.TRUE, "ID", Boolean.FALSE, null);
|
||||
metaDataService.getColumn(comicTable, "created_date", "created", "TIMESTAMP", null, 2, Boolean.FALSE, "", Boolean.FALSE, null);
|
||||
@@ -194,6 +196,7 @@ public class SetupModuleAdmin implements ApplicationListener<ContextRefreshedEve
|
||||
metaDataService.getColumn(comicTable, "current_order", "current_order", "BOOLEAN", null, 6, Boolean.TRUE, "Bestellung", Boolean.TRUE, "Bestellung");
|
||||
metaDataService.getColumn(comicTable, "title", "title", "TEXT", "UNIQUE", 7, Boolean.TRUE, "Title", Boolean.FALSE, null);
|
||||
metaDataService.getColumn(comicTable, "publisher_id", "publisher_id", "TEXT", null, 8, Boolean.TRUE, "Verlag", Boolean.FALSE, null, "name");
|
||||
metaDataService.getColumn(comicTable, "weblink", "weblink", "TEXT", null, 9, Boolean.TRUE, "Link", Boolean.FALSE, null);
|
||||
MetaDataTable issueTable = metaDataService.getTable("issue");
|
||||
metaDataService.getColumn(issueTable, "id", "identifier", "TEXT", "PRIMARY KEY", 1, Boolean.FALSE, "", Boolean.FALSE, null);
|
||||
metaDataService.getColumn(issueTable, "created_date", "created", "TIMESTAMP", null, 2, Boolean.FALSE, "", Boolean.FALSE, null);
|
||||
@@ -203,7 +206,8 @@ public class SetupModuleAdmin implements ApplicationListener<ContextRefreshedEve
|
||||
metaDataService.getColumn(issueTable, "is_read", "is_read", "BOOLEAN", null, 6, Boolean.FALSE, "", Boolean.FALSE, null);
|
||||
metaDataService.getColumn(issueTable, "issue_number", "issue_number", "TEXT", null, 7, Boolean.FALSE, "", Boolean.FALSE, null);
|
||||
metaDataService.getColumn(issueTable, "comic_id", "comic_id", "TEXT", null, 8, Boolean.FALSE, "", Boolean.FALSE, null, "title");
|
||||
metaDataService.getColumn(issueTable, "volume_id", "volume_id", "TEXT", null, 9, Boolean.FALSE, "", Boolean.FALSE, null);
|
||||
metaDataService.getColumn(issueTable, "volume_id", "volume_id", "TEXT", null, 9, Boolean.FALSE, "", Boolean.FALSE, null, "name");
|
||||
metaDataService.getColumn(issueTable, "story_arc_id", "story_arc_id", "TEXT", null, 10, Boolean.FALSE, "", Boolean.FALSE, null, "name");
|
||||
MetaDataTable volumeTable = metaDataService.getTable("volume");
|
||||
metaDataService.getColumn(volumeTable, "id", "identifier", "TEXT", "PRIMARY KEY", 1, Boolean.FALSE, "", Boolean.FALSE, null);
|
||||
metaDataService.getColumn(volumeTable, "created_date", "created", "TIMESTAMP", null, 2, Boolean.FALSE, "", Boolean.FALSE, null);
|
||||
@@ -226,7 +230,8 @@ public class SetupModuleAdmin implements ApplicationListener<ContextRefreshedEve
|
||||
metaDataService.getColumn(storyArcTable, "last_modified_date", "modified", "TIMESTAMP", null, 3, Boolean.FALSE, "", Boolean.FALSE, null);
|
||||
metaDataService.getColumn(storyArcTable, "version", "version", "LONG", null, 4, Boolean.FALSE, "", Boolean.FALSE, null);
|
||||
metaDataService.getColumn(storyArcTable, "name", "name", "TEXT", null, 5, Boolean.FALSE, "", Boolean.FALSE, null);
|
||||
metaDataService.getColumn(storyArcTable, "comic_id", "comic_id", "TEXT", null, 6, Boolean.FALSE, "", Boolean.FALSE, null);
|
||||
metaDataService.getColumn(storyArcTable, "comic_id", "comic_id", "TEXT", null, 6, Boolean.FALSE, "", Boolean.FALSE, null, "title");
|
||||
metaDataService.getColumn(storyArcTable, "volume_id", "volume_id", "TEXT", null, 7, Boolean.FALSE, "", Boolean.FALSE, null, "name");
|
||||
MetaDataTable worktypeTable = metaDataService.getTable("worktype");
|
||||
metaDataService.getColumn(worktypeTable, "id", "identifier", "TEXT", "PRIMARY KEY", 1, Boolean.FALSE, "", Boolean.FALSE, null);
|
||||
metaDataService.getColumn(worktypeTable, "created_date", "created", "TIMESTAMP", null, 2, Boolean.FALSE, "", Boolean.FALSE, null);
|
||||
|
||||
Reference in New Issue
Block a user