openlp/openlp/plugins/alerts/lib/db.py

55 lines
2.1 KiB
Python
Raw Normal View History

2010-02-14 13:27:32 +00:00
# -*- coding: utf-8 -*-
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
2022-02-06 09:10:17 +00:00
# Copyright (c) 2008-2022 OpenLP Developers #
2019-04-13 13:00:22 +00:00
# ---------------------------------------------------------------------- #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
##########################################################################
"""
2013-04-18 17:17:00 +00:00
The :mod:`db` module provides the database and schema that is the backend for the Alerts plugin.
"""
2010-02-14 13:27:32 +00:00
from sqlalchemy import Column, Table, types
from sqlalchemy.orm import mapper
from openlp.core.lib.db import BaseModel, init_db
2010-02-14 13:27:32 +00:00
2013-04-18 17:17:00 +00:00
2010-02-14 13:27:32 +00:00
class AlertItem(BaseModel):
"""
AlertItem model
2010-02-14 13:27:32 +00:00
"""
pass
2013-04-18 17:17:00 +00:00
def init_schema(url):
"""
Setup the alerts database connection and initialise the database schema
2014-01-01 09:33:07 +00:00
:param url:
The database to setup
"""
session, metadata = init_db(url)
2013-08-31 18:17:38 +00:00
alerts_table = Table('alerts', metadata,
2014-01-01 09:33:07 +00:00
Column('id', types.Integer(), primary_key=True),
Column('text', types.UnicodeText, nullable=False))
mapper(AlertItem, alerts_table)
2010-06-12 02:14:18 +00:00
metadata.create_all(checkfirst=True)
return session