
Changed license to AGPLv3, "finished" console command framework (for now?), and added initial db/lib/pyramid/wx subpackages - though those are not yet well tested.
109 lines
3.8 KiB
Python
109 lines
3.8 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
################################################################################
|
|
#
|
|
# edbob -- Pythonic Software Framework
|
|
# Copyright © 2010-2012 Lance Edgar
|
|
#
|
|
# This file is part of edbob.
|
|
#
|
|
# edbob is free software: you can redistribute it and/or modify it under the
|
|
# terms of the GNU Affero General Public License as published by the Free
|
|
# Software Foundation, either version 3 of the License, or (at your option)
|
|
# any later version.
|
|
#
|
|
# edbob 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 Affero General Public License for
|
|
# more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with edbob. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
################################################################################
|
|
|
|
"""
|
|
``edbob.db.model`` -- Core Schema Definition
|
|
"""
|
|
|
|
from sqlalchemy import *
|
|
|
|
from edbob import get_uuid
|
|
|
|
|
|
def get_metadata(*args, **kwargs):
|
|
"""
|
|
Returns the core ``edbob`` schema definition.
|
|
|
|
Note that when :func:`edbob.init()` is called, the ``sqlalchemy.MetaData``
|
|
instance which is returned from this function will henceforth be available
|
|
as ``edbob.metadata``. However, ``edbob.init()`` may extend
|
|
``edbob.metadata`` as well, depending on which extensions are activated
|
|
within the primary database.
|
|
|
|
This function then serves two purposes: First, it provides the core
|
|
metadata instance. Secondly, it allows edbob to always know what its core
|
|
schema looks like, as opposed to what's held in the current
|
|
``edbob.metadata`` instance, which may have been extended locally. (The
|
|
latter use is necessary in order for edbob to properly manage its
|
|
extensions.)
|
|
|
|
All arguments (positional and keyword) are passed directly to the
|
|
``sqlalchemy.MetaData()`` constructor.
|
|
"""
|
|
|
|
metadata = MetaData(*args, **kwargs)
|
|
|
|
active_extensions = Table(
|
|
'active_extensions', metadata,
|
|
Column('name', String(50), primary_key=True),
|
|
)
|
|
|
|
def get_person_display_name(context):
|
|
first_name = context.current_parameters['first_name']
|
|
last_name = context.current_parameters['last_name']
|
|
if not (first_name or last_name):
|
|
return None
|
|
return '%(first_name)s %(last_name)s' % locals()
|
|
|
|
people = Table(
|
|
'people', metadata,
|
|
Column('uuid', String(32), primary_key=True, default=get_uuid),
|
|
Column('first_name', String(50)),
|
|
Column('last_name', String(50)),
|
|
Column('display_name', String(100), default=get_person_display_name),
|
|
)
|
|
|
|
permissions = Table(
|
|
'permissions', metadata,
|
|
Column('role_uuid', String(32), ForeignKey('roles.uuid'), primary_key=True),
|
|
Column('permission', String(50), primary_key=True),
|
|
)
|
|
|
|
roles = Table(
|
|
'roles', metadata,
|
|
Column('uuid', String(32), primary_key=True, default=get_uuid),
|
|
Column('name', String(25), nullable=False, unique=True),
|
|
)
|
|
|
|
settings = Table(
|
|
'settings', metadata,
|
|
Column('name', String(255), primary_key=True),
|
|
Column('value', Text),
|
|
)
|
|
|
|
users = Table(
|
|
'users', metadata,
|
|
Column('uuid', String(32), primary_key=True, default=get_uuid),
|
|
Column('username', String(25), nullable=False, unique=True),
|
|
Column('person_uuid', String(32), ForeignKey('people.uuid')),
|
|
)
|
|
|
|
users_roles = Table(
|
|
'users_roles', metadata,
|
|
Column('uuid', String(32), primary_key=True, default=get_uuid),
|
|
Column('user_uuid', String(32), ForeignKey('users.uuid')),
|
|
Column('role_uuid', String(32), ForeignKey('roles.uuid')),
|
|
)
|
|
|
|
return metadata
|