This commit is contained in:
Nathan Rashleigh committed 2024-04-08 10:46:14 +10:00
1 parent d82a7fdf1e
commit 335eb8c4ac
16 files changed
+370 -5930

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
from db.base import Base
from db.attachment import Attachment
from db.meme import Meme
+15
View File
@@ -0,0 +1,15 @@
from sqlalchemy import create_engine, Column, Integer, String, JSON, Uuid
from db.base import Base
# Define a model with a JSON column
class Attachment(Base):
__tablename__ = 'attachments'
id = Column(Uuid, primary_key=True)
msg_id = Column(Integer, nullable=False, index=True)
attributes = Column(JSON, nullable=False)
vision = Column(JSON, nullable=False)
message = Column(JSON, nullable=False)
guild = Column(JSON, nullable=False)
channel = Column(JSON, nullable=False)
+3
View File
@@ -0,0 +1,3 @@
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
+12
View File
@@ -0,0 +1,12 @@
from sqlalchemy import Column, Integer, String, JSON, Uuid
from db.base import Base
# Define a model with a JSON column
class Meme(Base):
__tablename__ = 'memes'
id = Column(Uuid, primary_key=True)
url = Column(String, nullable=False)
text = Column(String, nullable=False)
tags = Column(JSON, nullable=False)
+16
View File
@@ -0,0 +1,16 @@
from sqlalchemy import create_engine, Column, Integer, String, Engine
from alembic.config import Config
from alembic import command
from dotenv import dotenv_values
# Function to perform the database migration
def migrate_db(engine: Engine, db_url):
# Configure Alembic
alembic_cfg = Config()
alembic_cfg.set_main_option("script_location", "migrations")
alembic_cfg.set_main_option("sqlalchemy.url", db_url)
# Run migrations using Alembic
command.upgrade(alembic_cfg, "head")
print('db up to date')