2007-02-12 22:39:14 +01:00
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
#
|
|
|
|
# Copyright (C) 2007 by Jan Dittberner.
|
|
|
|
#
|
|
|
|
# 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 2 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, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
|
|
# USA.
|
|
|
|
#
|
|
|
|
# Version: $Id$
|
|
|
|
|
|
|
|
from sqlalchemy import *
|
2007-07-05 11:00:34 +02:00
|
|
|
import sys
|
|
|
|
import migrate.versioning.api
|
|
|
|
from settings import *
|
2007-02-12 22:39:14 +01:00
|
|
|
|
2007-07-09 08:46:36 +02:00
|
|
|
try:
|
|
|
|
dbversion = migrate.versioning.api.db_version(
|
|
|
|
config.get('database', 'uri'),
|
|
|
|
config.get('database', 'repository'))
|
|
|
|
if dbversion < required_version:
|
|
|
|
print("""Database version is %d but required version is %d, run
|
2007-07-05 11:00:34 +02:00
|
|
|
|
|
|
|
migrate upgrade %s %s
|
|
|
|
|
|
|
|
to fix this.""" %
|
2007-07-09 08:46:36 +02:00
|
|
|
(dbversion, required_version, config.get('database', 'uri'),
|
|
|
|
config.get('database', 'repository')))
|
|
|
|
sys.exit(1)
|
|
|
|
except exceptions.NoSuchTableError, nste:
|
|
|
|
print nste
|
2007-07-05 11:00:34 +02:00
|
|
|
sys.exit(1)
|
2007-02-13 19:18:09 +01:00
|
|
|
|
|
|
|
meta = BoundMetaData(config.get('database', 'uri'))
|
2007-07-09 08:46:36 +02:00
|
|
|
#meta.engine.echo = True
|
2007-02-12 22:39:14 +01:00
|
|
|
client_table = Table(
|
2007-07-09 08:46:36 +02:00
|
|
|
'client', meta, schema = dbschema, autoload = True)
|
2007-02-12 22:39:14 +01:00
|
|
|
sysuser_table = Table(
|
2007-07-09 08:46:36 +02:00
|
|
|
'sysuser', meta, ForeignKeyConstraint(['clientid'], ['client.clientid']),
|
|
|
|
schema = dbschema, autoload = True)
|
2007-07-02 11:14:47 +02:00
|
|
|
domain_table = Table(
|
2007-07-09 08:46:36 +02:00
|
|
|
'domain', meta, ForeignKeyConstraint(['sysuserid'], ['sysuser.sysuserid']),
|
|
|
|
schema = dbschema, autoload = True)
|
2007-07-02 11:14:47 +02:00
|
|
|
record_table = Table(
|
2007-07-09 08:46:36 +02:00
|
|
|
'record', meta, ForeignKeyConstraint(['domainid'], ['domain.domainid']),
|
|
|
|
schema = dbschema, autoload = True)
|
2007-07-02 11:14:47 +02:00
|
|
|
supermaster_table = Table(
|
|
|
|
'supermaster', meta,
|
2007-07-09 08:46:36 +02:00
|
|
|
ForeignKeyConstraint(['account'], ['sysuser.sysuserid']),
|
|
|
|
schema = dbschema, autoload = True)
|
|
|
|
mailaccount_table = Table(
|
|
|
|
'mailaccount', meta,
|
|
|
|
ForeignKeyConstraint(['domainid'], ['domain.domainid']),
|
|
|
|
schema = dbschema, autoload = True)
|
|
|
|
mailaddress_table = Table(
|
|
|
|
'mailaddress', meta,
|
|
|
|
ForeignKeyConstraint(['domainid'], ['domain.domainid']),
|
|
|
|
schema = dbschema, autoload = True)
|
|
|
|
mailtarget_table = Table(
|
|
|
|
'mailtarget', meta,
|
|
|
|
ForeignKeyConstraint(['mailaddressid'], ['mailaddress.mailaddressid']),
|
|
|
|
schema = dbschema, autoload = True)
|