-- PostgreSQL database dump
--
-\restrict bCYCh5sZAo3Eaa8bUasedCV2H1jNs1GvAasBDDiQVe29BG0iu45omWev4EJu1ZQ
+\restrict MdBTHRTrPo5KwL7rBdfmjwUQ78IadFTz2sk6xzAeY0VTkdkQ2ifc9gAhyzISo3V
-- Dumped from database version 17.6 (Debian 17.6-0+deb13u1)
-- Dumped by pg_dump version 17.6 (Debian 17.6-0+deb13u1)
created_by text NOT NULL,
deleted_at timestamp with time zone,
deleted_by text,
- license text NOT NULL
+ license text NOT NULL,
+ updated_at timestamp with time zone
);
-- PostgreSQL database dump complete
--
-\unrestrict bCYCh5sZAo3Eaa8bUasedCV2H1jNs1GvAasBDDiQVe29BG0iu45omWev4EJu1ZQ
+\unrestrict MdBTHRTrPo5KwL7rBdfmjwUQ78IadFTz2sk6xzAeY0VTkdkQ2ifc9gAhyzISo3V
if exception is None:
session.commit()
+ def transaction(self):
+ """
+ Opens a new transaction
+ """
+ # Fetch our session
+ session = self.session()
+
+ # If we are already in a transaction, begin a nested one
+ if session.in_transaction():
+ return session.begin_nested()
+
+ # Otherwise begin the first transaction of the session
+ return session.begin()
+
def execute(self, stmt):
"""
Executes a statement and returns a result object
class List(sqlmodel.SQLModel, database.BackendMixin, table=True):
__tablename__ = "lists"
+ def __str__(self):
+ return self.name
+
# ID
id : int = sqlmodel.Field(primary_key=True)
# Sources
sources : typing.List["Source"] = sqlmodel.Relationship(back_populates="list")
+
+ # Updated At
+ updated_at : datetime.datetime | None
+
+ # Update!
+
+ def update(self):
+ """
+ Updates the list
+ """
+ with self.backend.db.transaction():
+ # Update the timestamp
+ self.updated_at = sqlmodel.func.current_timestamp()
+
+ # Update all sources
+ for source in self.sources:
+ source.update()
###############################################################################
import datetime
+import logging
import sqlmodel
from . import database
+# Setup logging
+log = logging.getLogger(__name__)
+
class Sources(object):
def __init__(self, backend):
self.backend = backend
class Source(sqlmodel.SQLModel, database.BackendMixin, table=True):
__tablename__ = "sources"
+ def __str__(self):
+ return self.name
+
# ID
id : int = sqlmodel.Field(primary_key=True)
# List
list : "List" = sqlmodel.Relationship(back_populates="sources")
+
+ def update(self):
+ """
+ Updates this source.
+ """
+ log.debug("%s: Updating source %s" % (self.list, self))
list_show.add_argument("list", help=_("The name of the list"))
list_show.set_defaults(func=self.__list_show)
+ # list-update
+ list_update = subparsers.add_parser("list-update", help=_("Updates a list"))
+ list_update.add_argument("list", help=_("The name of the list"))
+ list_update.set_defaults(func=self.__list_update)
+
# list-add-source
list_add_source = subparsers.add_parser("list-add-source",
help=_("Creates a new source to a list"))
# Print the sources
self.console.print(table)
+ def __list_update(self, backend, args):
+ """
+ Updates a single list
+ """
+ # Fetch the list
+ list = backend.lists.get_by_slug(args.list)
+
+ # Update!
+ list.update()
+
def __list_add_source(self, backend, args):
"""
Adds a new source to a list