()
| 799 | print("======================================\n") |
| 800 | |
| 801 | def run_migration_for_sqlite(): |
| 802 | # See pgadmin/__init__.py:run_migration_for_sqlite — tighten the |
| 803 | # umask so SQLite creates the DB file at 0o600 directly rather |
| 804 | # than relying on the post-hoc chmod (which has a TOCTOU window |
| 805 | # between create and chmod). |
| 806 | _saved_umask = os.umask(0o077) |
| 807 | try: |
| 808 | with app.app_context(): |
| 809 | # Run migration for the first time i.e. create database |
| 810 | from config import SQLITE_PATH |
| 811 | if not os.path.exists(SQLITE_PATH): |
| 812 | db_upgrade(app) |
| 813 | else: |
| 814 | version = Version.query.filter_by(name='ConfigDB').first() |
| 815 | schema_version = version.value |
| 816 | |
| 817 | # Run migration if current schema version is greater |
| 818 | # than the schema version stored in version table |
| 819 | if CURRENT_SCHEMA_VERSION >= schema_version: |
| 820 | db_upgrade(app) |
| 821 | |
| 822 | # Update schema version to the latest |
| 823 | if CURRENT_SCHEMA_VERSION > schema_version: |
| 824 | version = Version.query.filter_by( |
| 825 | name='ConfigDB').first() |
| 826 | version.value = CURRENT_SCHEMA_VERSION |
| 827 | db.session.commit() |
| 828 | finally: |
| 829 | os.umask(_saved_umask) |
| 830 | |
| 831 | if os.name != 'nt': |
| 832 | os.chmod(config.SQLITE_PATH, 0o600) |
| 833 | |
| 834 | def run_migration_for_others(): |
| 835 | with app.app_context(): |
no test coverage detected