kopia lustrzana https://github.com/glidernet/ogn-python
commit
141e92ba7c
|
@ -125,6 +125,7 @@ available commands:
|
||||||
import_ddb Import registered devices from the DDB.
|
import_ddb Import registered devices from the DDB.
|
||||||
import_file Import registered devices from a local file.
|
import_file Import registered devices from a local file.
|
||||||
init Initialize the database.
|
init Initialize the database.
|
||||||
|
upgrade Upgrade database to the latest version.
|
||||||
|
|
||||||
[gateway]
|
[gateway]
|
||||||
run Run the aprs client.
|
run Run the aprs client.
|
||||||
|
|
31
alembic.ini
31
alembic.ini
|
@ -1,37 +1,10 @@
|
||||||
# A generic, single database configuration.
|
# A single database configuration,
|
||||||
|
# sqlalchemy.url defined in env.py
|
||||||
|
|
||||||
[alembic]
|
[alembic]
|
||||||
# path to migration scripts
|
# path to migration scripts
|
||||||
script_location = alembic
|
script_location = alembic
|
||||||
|
|
||||||
# template used to generate migration files
|
|
||||||
# file_template = %%(rev)s_%%(slug)s
|
|
||||||
|
|
||||||
# max length of characters to apply to the
|
|
||||||
# "slug" field
|
|
||||||
#truncate_slug_length = 40
|
|
||||||
|
|
||||||
# set to 'true' to run the environment during
|
|
||||||
# the 'revision' command, regardless of autogenerate
|
|
||||||
# revision_environment = false
|
|
||||||
|
|
||||||
# set to 'true' to allow .pyc and .pyo files without
|
|
||||||
# a source .py file to be detected as revisions in the
|
|
||||||
# versions/ directory
|
|
||||||
# sourceless = false
|
|
||||||
|
|
||||||
# version location specification; this defaults
|
|
||||||
# to alembic/versions. When using multiple version
|
|
||||||
# directories, initial revisions must be specified with --version-path
|
|
||||||
# version_locations = %(here)s/bar %(here)s/bat alembic/versions
|
|
||||||
|
|
||||||
# the output encoding used when revision files
|
|
||||||
# are written from script.py.mako
|
|
||||||
# output_encoding = utf-8
|
|
||||||
|
|
||||||
sqlalchemy.url = sqlite:///beacons.db
|
|
||||||
|
|
||||||
|
|
||||||
# Logging configuration
|
# Logging configuration
|
||||||
[loggers]
|
[loggers]
|
||||||
keys = root,sqlalchemy,alembic
|
keys = root,sqlalchemy,alembic
|
||||||
|
|
|
@ -1,26 +1,27 @@
|
||||||
from __future__ import with_statement
|
import os
|
||||||
|
import importlib
|
||||||
|
|
||||||
from alembic import context
|
from alembic import context
|
||||||
from sqlalchemy import engine_from_config, pool
|
from sqlalchemy import engine_from_config, pool
|
||||||
from logging.config import fileConfig
|
from logging.config import fileConfig
|
||||||
|
|
||||||
# this is the Alembic Config object, which provides
|
|
||||||
# access to the values within the .ini file in use.
|
# Provides access to the values within the .ini file in use.
|
||||||
config = context.config
|
alembic_config = context.config
|
||||||
|
|
||||||
# Interpret the config file for Python logging.
|
# Interpret the config file for Python logging.
|
||||||
# This line sets up loggers basically.
|
# This line sets up loggers basically.
|
||||||
fileConfig(config.config_file_name)
|
fileConfig(alembic_config.config_file_name)
|
||||||
|
|
||||||
# add your model's MetaData object here
|
# Get database path from ogn config
|
||||||
# for 'autogenerate' support
|
os.environ.setdefault('OGN_CONFIG_MODULE', 'config.default')
|
||||||
# from myapp import mymodel
|
ogn_config = importlib.import_module(os.environ['OGN_CONFIG_MODULE'])
|
||||||
# target_metadata = mymodel.Base.metadata
|
|
||||||
target_metadata = None
|
|
||||||
|
|
||||||
# other values from the config, defined by the needs of env.py,
|
alembic_config.set_main_option('sqlalchemy.url', ogn_config.SQLALCHEMY_DATABASE_URI)
|
||||||
# can be acquired:
|
|
||||||
# my_important_option = config.get_main_option("my_important_option")
|
# Import metadata for autogeneration of migrations
|
||||||
# ... etc.
|
from ogn.model import Base
|
||||||
|
target_metadata = Base.metadata
|
||||||
|
|
||||||
|
|
||||||
def run_migrations_offline():
|
def run_migrations_offline():
|
||||||
|
@ -51,7 +52,7 @@ def run_migrations_online():
|
||||||
|
|
||||||
"""
|
"""
|
||||||
connectable = engine_from_config(
|
connectable = engine_from_config(
|
||||||
config.get_section(config.config_ini_section),
|
alembic_config.get_section(alembic_config.config_ini_section),
|
||||||
prefix='sqlalchemy.',
|
prefix='sqlalchemy.',
|
||||||
poolclass=pool.NullPool)
|
poolclass=pool.NullPool)
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ from ogn.collect.database import update_devices
|
||||||
from manager import Manager
|
from manager import Manager
|
||||||
manager = Manager()
|
manager = Manager()
|
||||||
|
|
||||||
|
ALEMBIC_CONFIG_FILE = "alembic.ini"
|
||||||
|
|
||||||
|
|
||||||
@manager.command
|
@manager.command
|
||||||
def init():
|
def init():
|
||||||
|
@ -15,11 +17,22 @@ def init():
|
||||||
from alembic import command
|
from alembic import command
|
||||||
|
|
||||||
Base.metadata.create_all(engine)
|
Base.metadata.create_all(engine)
|
||||||
alembic_cfg = Config("alembic.ini")
|
alembic_cfg = Config(ALEMBIC_CONFIG_FILE)
|
||||||
command.stamp(alembic_cfg, "head")
|
command.stamp(alembic_cfg, "head")
|
||||||
print("Done.")
|
print("Done.")
|
||||||
|
|
||||||
|
|
||||||
|
@manager.command
|
||||||
|
def upgrade():
|
||||||
|
"""Upgrade database to the latest version."""
|
||||||
|
|
||||||
|
from alembic.config import Config
|
||||||
|
from alembic import command
|
||||||
|
|
||||||
|
alembic_cfg = Config(ALEMBIC_CONFIG_FILE)
|
||||||
|
command.upgrade(alembic_cfg, 'head')
|
||||||
|
|
||||||
|
|
||||||
@manager.command
|
@manager.command
|
||||||
def drop(sure='n'):
|
def drop(sure='n'):
|
||||||
"""Drop all tables."""
|
"""Drop all tables."""
|
||||||
|
|
Ładowanie…
Reference in New Issue