2015-06-30 11:21:55 +05:30
|
|
|
#########################################################################
|
2015-01-22 15:56:23 +00:00
|
|
|
#
|
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
|
#
|
2018-01-05 10:42:49 +00:00
|
|
|
# Copyright (C) 2013 - 2018, The pgAdmin Development Team
|
2015-01-22 15:56:23 +00:00
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
|
#
|
|
|
|
|
##########################################################################
|
|
|
|
|
|
|
|
|
|
"""Perform the initial setup of the application, by creating the auth
|
|
|
|
|
and settings database."""
|
|
|
|
|
|
2016-06-21 14:12:14 +01:00
|
|
|
import os
|
|
|
|
|
import sys
|
2017-08-29 15:03:02 +01:00
|
|
|
from pgadmin.model import db, Version, SCHEMA_VERSION as CURRENT_SCHEMA_VERSION
|
2015-10-20 12:33:18 +05:30
|
|
|
|
2017-08-25 11:56:44 +01:00
|
|
|
if sys.version_info[0] >= 3:
|
|
|
|
|
import builtins
|
|
|
|
|
else:
|
|
|
|
|
import __builtin__ as builtins
|
|
|
|
|
|
|
|
|
|
# Grab the SERVER_MODE if it's been set by the runtime
|
|
|
|
|
if 'SERVER_MODE' in globals():
|
|
|
|
|
builtins.SERVER_MODE = globals()['SERVER_MODE']
|
|
|
|
|
else:
|
|
|
|
|
builtins.SERVER_MODE = None
|
2016-06-21 14:12:14 +01:00
|
|
|
|
2017-03-07 15:30:57 +05:30
|
|
|
# We need to include the root directory in sys.path to ensure that we can
|
|
|
|
|
# find everything we need when running in the standalone runtime.
|
|
|
|
|
root = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
if sys.path[0] != root:
|
|
|
|
|
sys.path.insert(0, root)
|
|
|
|
|
|
2017-07-10 16:08:35 +01:00
|
|
|
from pgadmin import create_app
|
|
|
|
|
|
2017-04-24 08:36:55 +05:30
|
|
|
if __name__ == '__main__':
|
|
|
|
|
# Configuration settings
|
|
|
|
|
import config
|
2017-07-10 16:08:35 +01:00
|
|
|
from pgadmin.model import SCHEMA_VERSION
|
2017-04-24 08:36:55 +05:30
|
|
|
from pgadmin.setup import db_upgrade, create_app_data_directory
|
2017-03-07 15:30:57 +05:30
|
|
|
|
2017-04-24 08:36:55 +05:30
|
|
|
config.SETTINGS_SCHEMA_VERSION = SCHEMA_VERSION
|
2017-06-16 10:17:38 +01:00
|
|
|
if "PGADMIN_TESTING_MODE" in os. environ and \
|
2018-01-26 16:54:21 +00:00
|
|
|
os.environ["PGADMIN_TESTING_MODE"] == "1":
|
2016-09-14 16:26:12 +01:00
|
|
|
config.SQLITE_PATH = config.TEST_SQLITE_PATH
|
2018-01-26 16:54:21 +00:00
|
|
|
|
2017-04-24 08:36:55 +05:30
|
|
|
create_app_data_directory(config)
|
|
|
|
|
|
2017-07-10 16:08:35 +01:00
|
|
|
app = create_app()
|
2015-07-22 22:12:39 +05:30
|
|
|
|
2017-03-07 15:30:57 +05:30
|
|
|
print(u"pgAdmin 4 - Application Initialisation")
|
|
|
|
|
print(u"======================================\n")
|
|
|
|
|
|
2017-07-10 16:08:35 +01:00
|
|
|
with app.app_context():
|
2017-08-29 15:03:02 +01:00
|
|
|
# Run migration for the first time i.e. create database
|
|
|
|
|
from config import SQLITE_PATH
|
|
|
|
|
if not os.path.exists(SQLITE_PATH):
|
|
|
|
|
db_upgrade(app)
|
|
|
|
|
else:
|
|
|
|
|
version = Version.query.filter_by(name='ConfigDB').first()
|
|
|
|
|
schema_version = version.value
|
|
|
|
|
|
|
|
|
|
# Run migration if current schema version is greater than the
|
|
|
|
|
# schema version stored in version table
|
|
|
|
|
if CURRENT_SCHEMA_VERSION >= schema_version:
|
|
|
|
|
db_upgrade(app)
|
|
|
|
|
|
|
|
|
|
# Update schema version to the latest
|
|
|
|
|
if CURRENT_SCHEMA_VERSION > schema_version:
|
|
|
|
|
version = Version.query.filter_by(name='ConfigDB').first()
|
|
|
|
|
version.value = CURRENT_SCHEMA_VERSION
|
|
|
|
|
db.session.commit()
|