2015-01-22 09:56:23 -06:00
|
|
|
##########################################################################
|
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
2015-02-25 14:25:41 -06:00
|
|
|
# Copyright (C) 2013 - 2015, The pgAdmin Development Team
|
2015-01-22 09:56:23 -06:00
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
#
|
|
|
|
##########################################################################
|
|
|
|
|
2015-03-09 10:06:10 -05:00
|
|
|
"""Defines the models for the configuration database.
|
|
|
|
|
2015-06-29 01:42:27 -05:00
|
|
|
If any of the models are updated, you (yes, you, the developer) MUST do two
|
2015-03-09 10:06:10 -05:00
|
|
|
things:
|
|
|
|
|
|
|
|
1) Increment SETTINGS_SCHEMA_VERSION in config.py
|
|
|
|
|
2015-10-20 02:03:18 -05:00
|
|
|
2) Modify setup.py to ensure that the appropriate changes are made to the
|
|
|
|
config database to upgrade it to the new version.
|
2015-03-09 10:06:10 -05:00
|
|
|
"""
|
2015-01-22 09:56:23 -06:00
|
|
|
|
|
|
|
from flask.ext.sqlalchemy import SQLAlchemy
|
|
|
|
from flask.ext.security import UserMixin, RoleMixin
|
|
|
|
|
|
|
|
db = SQLAlchemy()
|
|
|
|
|
|
|
|
# Define models
|
2015-10-20 02:03:18 -05:00
|
|
|
roles_users = db.Table(
|
|
|
|
'roles_users',
|
|
|
|
db.Column('user_id', db.Integer(), db.ForeignKey('user.id')),
|
|
|
|
db.Column('role_id', db.Integer(), db.ForeignKey('role.id'))
|
|
|
|
)
|
2015-01-22 09:56:23 -06:00
|
|
|
|
2015-06-29 01:42:27 -05:00
|
|
|
|
2015-03-09 10:06:10 -05:00
|
|
|
class Version(db.Model):
|
|
|
|
"""Version numbers for reference/upgrade purposes"""
|
|
|
|
__tablename__ = 'version'
|
|
|
|
name = db.Column(db.String(32), primary_key=True)
|
|
|
|
value = db.Column(db.Integer(), nullable=False)
|
2015-06-29 01:42:27 -05:00
|
|
|
|
2015-10-20 02:03:18 -05:00
|
|
|
|
2015-01-22 09:56:23 -06:00
|
|
|
class Role(db.Model, RoleMixin):
|
|
|
|
"""Define a security role"""
|
2015-02-03 05:48:15 -06:00
|
|
|
__tablename__ = 'role'
|
2015-01-22 09:56:23 -06:00
|
|
|
id = db.Column(db.Integer(), primary_key=True)
|
2015-03-09 10:06:10 -05:00
|
|
|
name = db.Column(db.String(128), unique=True, nullable=False)
|
|
|
|
description = db.Column(db.String(256), nullable=False)
|
2015-01-22 09:56:23 -06:00
|
|
|
|
2015-10-20 02:03:18 -05:00
|
|
|
|
2015-01-22 09:56:23 -06:00
|
|
|
class User(db.Model, UserMixin):
|
|
|
|
"""Define a user object"""
|
2015-02-03 05:48:15 -06:00
|
|
|
__tablename__ = 'user'
|
2015-01-22 09:56:23 -06:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2015-03-09 10:06:10 -05:00
|
|
|
email = db.Column(db.String(256), unique=True, nullable=False)
|
|
|
|
password = db.Column(db.String(256))
|
|
|
|
active = db.Column(db.Boolean(), nullable=False)
|
2015-01-22 09:56:23 -06:00
|
|
|
confirmed_at = db.Column(db.DateTime())
|
|
|
|
roles = db.relationship('Role', secondary=roles_users,
|
|
|
|
backref=db.backref('users', lazy='dynamic'))
|
2015-06-29 01:42:27 -05:00
|
|
|
|
2015-10-20 02:03:18 -05:00
|
|
|
|
2015-02-03 05:48:15 -06:00
|
|
|
class Setting(db.Model):
|
|
|
|
"""Define a setting object"""
|
|
|
|
__tablename__ = 'setting'
|
|
|
|
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
|
2015-03-09 10:06:10 -05:00
|
|
|
setting = db.Column(db.String(256), primary_key=True)
|
2015-02-11 04:00:57 -06:00
|
|
|
value = db.Column(db.String(1024))
|
2015-03-09 10:06:10 -05:00
|
|
|
|
2015-10-20 02:03:18 -05:00
|
|
|
|
2015-02-13 07:13:36 -06:00
|
|
|
class ServerGroup(db.Model):
|
|
|
|
"""Define a server group for the treeview"""
|
|
|
|
__tablename__ = 'servergroup'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2015-03-09 10:06:10 -05:00
|
|
|
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
|
2015-06-29 03:11:56 -05:00
|
|
|
|
2015-03-09 10:06:10 -05:00
|
|
|
name = db.Column(db.String(128), nullable=False)
|
2015-02-13 07:13:36 -06:00
|
|
|
__table_args__ = (db.UniqueConstraint('user_id', 'name'),)
|
2015-06-29 01:42:27 -05:00
|
|
|
|
2015-03-09 10:06:10 -05:00
|
|
|
|
|
|
|
class Server(db.Model):
|
|
|
|
"""Define a registered Postgres server"""
|
|
|
|
__tablename__ = 'server'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2015-06-29 03:11:56 -05:00
|
|
|
user_id = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey('user.id'),
|
|
|
|
nullable=False
|
|
|
|
)
|
|
|
|
servergroup_id = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey('servergroup.id'),
|
|
|
|
nullable=False
|
|
|
|
)
|
2015-03-09 10:06:10 -05:00
|
|
|
name = db.Column(db.String(128), nullable=False)
|
|
|
|
host = db.Column(db.String(128), nullable=False)
|
2015-06-29 03:11:56 -05:00
|
|
|
port = db.Column(
|
|
|
|
db.Integer(),
|
|
|
|
db.CheckConstraint('port >= 1024 AND port <= 65534'),
|
|
|
|
nullable=False)
|
2015-03-09 10:06:10 -05:00
|
|
|
maintenance_db = db.Column(db.String(64), nullable=False)
|
|
|
|
username = db.Column(db.String(64), nullable=False)
|
2015-10-20 02:03:18 -05:00
|
|
|
password = db.Column(db.String(64), nullable=True)
|
|
|
|
role = db.Column(db.String(64), nullable=True)
|
2015-06-29 03:11:56 -05:00
|
|
|
ssl_mode = db.Column(
|
2015-06-30 00:51:55 -05:00
|
|
|
db.String(16),
|
|
|
|
db.CheckConstraint(
|
|
|
|
"ssl_mode IN ('allow', 'prefer', 'require', 'disable', 'verify-ca', 'verify-full')"
|
|
|
|
),
|
|
|
|
nullable=False)
|
|
|
|
comment = db.Column(
|
|
|
|
db.String(1024),
|
|
|
|
nullable=True)
|