2015-06-30 00:51:55 -05:00
|
|
|
#########################################################################
|
2015-01-22 09:56:23 -06:00
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
2018-01-05 04:42:49 -06:00
|
|
|
# Copyright (C) 2013 - 2018, The pgAdmin Development Team
|
2015-01-22 09:56:23 -06: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 08:12:14 -05:00
|
|
|
import os
|
|
|
|
import sys
|
2017-08-29 09:03:02 -05:00
|
|
|
from pgadmin.model import db, Version, SCHEMA_VERSION as CURRENT_SCHEMA_VERSION
|
2015-10-20 02:03:18 -05:00
|
|
|
|
2017-08-25 05:56:44 -05: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 08:12:14 -05:00
|
|
|
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
# 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 10:08:35 -05:00
|
|
|
from pgadmin import create_app
|
|
|
|
|
2017-04-23 22:06:55 -05:00
|
|
|
if __name__ == '__main__':
|
|
|
|
# Configuration settings
|
|
|
|
import config
|
2017-07-10 10:08:35 -05:00
|
|
|
from pgadmin.model import SCHEMA_VERSION
|
2017-04-23 22:06:55 -05:00
|
|
|
from pgadmin.setup import db_upgrade, create_app_data_directory
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
|
2017-04-23 22:06:55 -05:00
|
|
|
config.SETTINGS_SCHEMA_VERSION = SCHEMA_VERSION
|
2017-06-16 04:17:38 -05:00
|
|
|
if "PGADMIN_TESTING_MODE" in os. environ and \
|
2018-01-26 10:54:21 -06:00
|
|
|
os.environ["PGADMIN_TESTING_MODE"] == "1":
|
2016-09-14 10:26:12 -05:00
|
|
|
config.SQLITE_PATH = config.TEST_SQLITE_PATH
|
2018-01-26 10:54:21 -06:00
|
|
|
|
2017-04-23 22:06:55 -05:00
|
|
|
create_app_data_directory(config)
|
|
|
|
|
2017-07-10 10:08:35 -05:00
|
|
|
app = create_app()
|
2015-07-22 11:42:39 -05:00
|
|
|
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
print(u"pgAdmin 4 - Application Initialisation")
|
|
|
|
print(u"======================================\n")
|
|
|
|
|
2017-07-10 10:08:35 -05:00
|
|
|
with app.app_context():
|
2017-08-29 09:03:02 -05: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()
|