update scripts to use Postgres
This commit is contained in:
@@ -23,12 +23,12 @@ def copy_data(postgres_conn, data_file: Path, log):
|
|||||||
log.info("read json file")
|
log.info("read json file")
|
||||||
with open(data_file, 'r') as json_file:
|
with open(data_file, 'r') as json_file:
|
||||||
json_load = json.load(json_file)
|
json_load = json.load(json_file)
|
||||||
|
postgres_cursor.execute("SET session_replication_role='replica'")
|
||||||
for table in json_load:
|
for table in json_load:
|
||||||
log.info(f"{table}: {len(json_load[table])}")
|
log.info(f"{table}: {len(json_load[table])}")
|
||||||
# result[table] = import_table(table, json_load[table])
|
# result[table] = import_table(table, json_load[table])
|
||||||
truncate_statement = 'TRUNCATE {}'.format(table)
|
truncate_statement = 'TRUNCATE {} CASCADE'.format(table)
|
||||||
#log.info(f"truncate: {truncate_statement}")
|
#log.info(f"truncate: {truncate_statement}")
|
||||||
postgres_cursor.execute("SET FOREIGN_KEY_CHECKS = 0")
|
|
||||||
postgres_cursor.execute(truncate_statement)
|
postgres_cursor.execute(truncate_statement)
|
||||||
items = json_load[table]
|
items = json_load[table]
|
||||||
for item in items:
|
for item in items:
|
||||||
@@ -47,7 +47,7 @@ def copy_data(postgres_conn, data_file: Path, log):
|
|||||||
postgres_conn.commit()
|
postgres_conn.commit()
|
||||||
except psycopg2.Error as error:
|
except psycopg2.Error as error:
|
||||||
log.info('insert failed with %s', error)
|
log.info('insert failed with %s', error)
|
||||||
|
postgres_cursor.execute("SET session_replication_role='origin'")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logger = get_logger(args.verbose, args.config)
|
logger = get_logger(args.verbose, args.config)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from sqlalchemy import Column, ForeignKey, Integer, String
|
from sqlalchemy import Column, ForeignKey, Integer, String, Boolean
|
||||||
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
|
||||||
@@ -56,7 +55,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(BIT(1))
|
import_data = Column(Boolean)
|
||||||
|
|
||||||
|
|
||||||
class MailAccount(Base, BaseMixin):
|
class MailAccount(Base, BaseMixin):
|
||||||
@@ -66,7 +65,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(BIT(1))
|
start_tls = Column(Boolean)
|
||||||
|
|
||||||
|
|
||||||
class Mail(Base, BaseMixin):
|
class Mail(Base, BaseMixin):
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from sqlalchemy import func, Column, String
|
from sqlalchemy import func, Column, String, Boolean
|
||||||
from sqlalchemy.dialects.mysql import BIT
|
|
||||||
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
||||||
|
|
||||||
|
|
||||||
@@ -25,7 +24,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(BIT(1))
|
review = Column(Boolean)
|
||||||
title = Column(String(255))
|
title = Column(String(255))
|
||||||
url = Column(String(255), unique=True)
|
url = Column(String(255), unique=True)
|
||||||
should_download = Column(BIT(1))
|
should_download = Column(Boolean)
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from sqlalchemy import Column, ForeignKey, Integer, String
|
from sqlalchemy import Column, ForeignKey, Integer, String, Boolean
|
||||||
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
|
||||||
@@ -22,8 +21,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(BIT(1))
|
current_order = Column(Boolean)
|
||||||
completed = Column(BIT(1))
|
completed = Column(Boolean)
|
||||||
issues = relationship("Issue")
|
issues = relationship("Issue")
|
||||||
story_arcs = relationship("StoryArc")
|
story_arcs = relationship("StoryArc")
|
||||||
trade_paperbacks = relationship("TradePaperback")
|
trade_paperbacks = relationship("TradePaperback")
|
||||||
@@ -64,8 +63,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(BIT(1))
|
in_stock = Column(Boolean)
|
||||||
is_read = Column(BIT(1))
|
is_read = Column(Boolean)
|
||||||
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)
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from sqlalchemy import Column, String, ForeignKey, Integer
|
from sqlalchemy import Column, String, ForeignKey, Integer, Boolean
|
||||||
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
|
||||||
@@ -28,8 +27,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(BIT(1))
|
is_shown = Column(Boolean)
|
||||||
show_filter = Column(BIT(1))
|
show_filter = Column(Boolean)
|
||||||
ref_column = Column(String, nullable=True)
|
ref_column = Column(String, nullable=True)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from sqlalchemy import Column, Integer, String, ForeignKey, UniqueConstraint
|
from sqlalchemy import Column, Integer, String, ForeignKey, UniqueConstraint, Boolean
|
||||||
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
|
||||||
@@ -78,8 +77,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(BIT(1))
|
parallel_set = Column(Boolean)
|
||||||
insert_set = Column(BIT(1))
|
insert_set = Column(Boolean)
|
||||||
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