mirror of
https://github.com/yandex/pgmigrate.git
synced 2024-09-17 15:17:18 +03:00
Bump deps versions
This commit is contained in:
parent
8f109e797d
commit
ed897ffb97
@ -13,7 +13,7 @@ ENV DEBIAN_FRONTEND noninteractive
|
|||||||
|
|
||||||
RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
|
RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
|
||||||
|
|
||||||
ENV PG_MAJOR 10
|
ENV PG_MAJOR 11
|
||||||
|
|
||||||
RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list
|
RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list
|
||||||
|
|
||||||
|
@ -40,18 +40,19 @@ def step_impl(context):
|
|||||||
@given('successful pgmigrate run with our callbacks and "{args}"') # noqa
|
@given('successful pgmigrate run with our callbacks and "{args}"') # noqa
|
||||||
def step_impl(context, args):
|
def step_impl(context, args):
|
||||||
cbs = ','.join(context.callbacks)
|
cbs = ','.join(context.callbacks)
|
||||||
context.execute_steps('given successful pgmigrate run with ' +
|
context.execute_steps('given successful pgmigrate run with ' + '"%s"' %
|
||||||
'"%s"' % ('-a ' + cbs + ' ' + args,))
|
('-a ' + cbs + ' ' + args, ))
|
||||||
|
|
||||||
|
|
||||||
@when('we run pgmigrate with our callbacks and "{args}"') # noqa
|
@when('we run pgmigrate with our callbacks and "{args}"') # noqa
|
||||||
def step_impl(context, args):
|
def step_impl(context, args):
|
||||||
cbs = ','.join(context.callbacks)
|
cbs = ','.join(context.callbacks)
|
||||||
context.execute_steps('when we run pgmigrate with ' +
|
context.execute_steps('when we run pgmigrate with ' + '"%s"' %
|
||||||
'"%s"' % ('-a ' + cbs + ' ' + args,))
|
('-a ' + cbs + ' ' + args, ))
|
||||||
|
|
||||||
|
|
||||||
@when('we run pgmigrate with dir callbacks and type "{cb_type}" and "{args}"') # noqa
|
@when('we run pgmigrate with dir callbacks and type "{cb_type}" and "{args}"'
|
||||||
|
) # noqa
|
||||||
def step_impl(context, cb_type, args):
|
def step_impl(context, cb_type, args):
|
||||||
p_args = '-a ' + cb_type + ':' + context.migr_dir + '/callbacks/ ' + args
|
p_args = '-a ' + cb_type + ':' + context.migr_dir + '/callbacks/ ' + args
|
||||||
context.execute_steps('when we run pgmigrate with "%s"' % (p_args,))
|
context.execute_steps('when we run pgmigrate with "%s"' % (p_args, ))
|
||||||
|
@ -9,12 +9,12 @@ from behave import given, then, when
|
|||||||
|
|
||||||
|
|
||||||
def run_pgmigrate(migr_dir, args):
|
def run_pgmigrate(migr_dir, args):
|
||||||
cmd = ['coverage', 'run', '-p', '--include=pgmigrate.py',
|
cmd = [
|
||||||
'./pgmigrate.py', '-vvv', '-d', migr_dir,
|
'coverage', 'run', '-p', '--include=pgmigrate.py', './pgmigrate.py',
|
||||||
'-c', 'dbname=pgmigratetest'] + str(args).split(' ')
|
'-vvv', '-d', migr_dir, '-c', 'dbname=pgmigratetest'
|
||||||
|
] + str(args).split(' ')
|
||||||
|
|
||||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
stderr=subprocess.PIPE)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
stdout, stderr = func_timeout(5, p.communicate)
|
stdout, stderr = func_timeout(5, p.communicate)
|
||||||
@ -23,11 +23,16 @@ def run_pgmigrate(migr_dir, args):
|
|||||||
stdout, stderr = p.communicate()
|
stdout, stderr = p.communicate()
|
||||||
return p.returncode, str(stdout), str(stderr)
|
return p.returncode, str(stdout), str(stderr)
|
||||||
|
|
||||||
|
|
||||||
@given('successful pgmigrate run with "{args}"')
|
@given('successful pgmigrate run with "{args}"')
|
||||||
def step_impl(context, args):
|
def step_impl(context, args):
|
||||||
if context.migrate_config:
|
if context.migrate_config:
|
||||||
with open(os.path.join(context.migr_dir, 'migrations.yml'), 'w') as f:
|
with open(os.path.join(context.migr_dir, 'migrations.yml'), 'w') as f:
|
||||||
f.write(yaml.dump(context.migrate_config))
|
yaml.safe_dump(context.migrate_config,
|
||||||
|
f,
|
||||||
|
encoding=None,
|
||||||
|
default_flow_style=False,
|
||||||
|
allow_unicode=True)
|
||||||
res = run_pgmigrate(context.migr_dir, args)
|
res = run_pgmigrate(context.migr_dir, args)
|
||||||
|
|
||||||
if res[0] != 0:
|
if res[0] != 0:
|
||||||
@ -40,7 +45,11 @@ def step_impl(context, args):
|
|||||||
def step_impl(context, args):
|
def step_impl(context, args):
|
||||||
if context.migrate_config:
|
if context.migrate_config:
|
||||||
with open(os.path.join(context.migr_dir, 'migrations.yml'), 'w') as f:
|
with open(os.path.join(context.migr_dir, 'migrations.yml'), 'w') as f:
|
||||||
f.write(yaml.dump(context.migrate_config))
|
yaml.safe_dump(context.migrate_config,
|
||||||
|
f,
|
||||||
|
encoding=None,
|
||||||
|
default_flow_style=False,
|
||||||
|
allow_unicode=True)
|
||||||
res = run_pgmigrate(context.migr_dir, args)
|
res = run_pgmigrate(context.migr_dir, args)
|
||||||
|
|
||||||
context.last_migrate_res = {'ret': res[0], 'out': res[1], 'err': res[2]}
|
context.last_migrate_res = {'ret': res[0], 'out': res[1], 'err': res[2]}
|
||||||
|
118
pgmigrate.py
118
pgmigrate.py
@ -50,42 +50,36 @@ class MigrateError(RuntimeError):
|
|||||||
"""
|
"""
|
||||||
Common migration error class
|
Common migration error class
|
||||||
"""
|
"""
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class MalformedStatement(MigrateError):
|
class MalformedStatement(MigrateError):
|
||||||
"""
|
"""
|
||||||
Incorrect statement exception
|
Incorrect statement exception
|
||||||
"""
|
"""
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class MalformedMigration(MigrateError):
|
class MalformedMigration(MigrateError):
|
||||||
"""
|
"""
|
||||||
Incorrect migration exception
|
Incorrect migration exception
|
||||||
"""
|
"""
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class MalformedSchema(MigrateError):
|
class MalformedSchema(MigrateError):
|
||||||
"""
|
"""
|
||||||
Incorrect schema exception
|
Incorrect schema exception
|
||||||
"""
|
"""
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class ConfigurationError(MigrateError):
|
class ConfigurationError(MigrateError):
|
||||||
"""
|
"""
|
||||||
Incorrect config or cmd args exception
|
Incorrect config or cmd args exception
|
||||||
"""
|
"""
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class BaselineError(MigrateError):
|
class BaselineError(MigrateError):
|
||||||
"""
|
"""
|
||||||
Baseline error class
|
Baseline error class
|
||||||
"""
|
"""
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class ConflictTerminator(threading.Thread):
|
class ConflictTerminator(threading.Thread):
|
||||||
@ -703,20 +697,19 @@ COMMANDS = {
|
|||||||
'migrate': migrate,
|
'migrate': migrate,
|
||||||
}
|
}
|
||||||
|
|
||||||
CONFIG_DEFAULTS = Config(
|
CONFIG_DEFAULTS = Config(target=None,
|
||||||
target=None,
|
baseline=0,
|
||||||
baseline=0,
|
cursor=None,
|
||||||
cursor=None,
|
dryrun=False,
|
||||||
dryrun=False,
|
callbacks='',
|
||||||
callbacks='',
|
base_dir='',
|
||||||
base_dir='',
|
user=None,
|
||||||
user=None,
|
session=['SET lock_timeout = 0'],
|
||||||
session=['SET lock_timeout = 0'],
|
conn='dbname=postgres user=postgres '
|
||||||
conn='dbname=postgres user=postgres '
|
'connect_timeout=1',
|
||||||
'connect_timeout=1',
|
conn_instance=None,
|
||||||
conn_instance=None,
|
terminator_instance=None,
|
||||||
terminator_instance=None,
|
termination_interval=None)
|
||||||
termination_interval=None)
|
|
||||||
|
|
||||||
|
|
||||||
def get_config(base_dir, args=None):
|
def get_config(base_dir, args=None):
|
||||||
@ -726,7 +719,7 @@ def get_config(base_dir, args=None):
|
|||||||
path = os.path.join(base_dir, 'migrations.yml')
|
path = os.path.join(base_dir, 'migrations.yml')
|
||||||
try:
|
try:
|
||||||
with codecs.open(path, encoding='utf-8') as i:
|
with codecs.open(path, encoding='utf-8') as i:
|
||||||
base = yaml.load(i.read())
|
base = yaml.safe_load(i)
|
||||||
except IOError:
|
except IOError:
|
||||||
LOG.info('Unable to load %s. Using defaults', path)
|
LOG.info('Unable to load %s. Using defaults', path)
|
||||||
base = {}
|
base = {}
|
||||||
@ -746,9 +739,8 @@ def get_config(base_dir, args=None):
|
|||||||
conf = conf._replace(target=int(conf.target))
|
conf = conf._replace(target=int(conf.target))
|
||||||
|
|
||||||
if conf.termination_interval and not conf.dryrun:
|
if conf.termination_interval and not conf.dryrun:
|
||||||
conf = conf._replace(
|
conf = conf._replace(terminator_instance=ConflictTerminator(
|
||||||
terminator_instance=ConflictTerminator(conf.conn,
|
conf.conn, conf.termination_interval))
|
||||||
conf.termination_interval))
|
|
||||||
conf.terminator_instance.start()
|
conf.terminator_instance.start()
|
||||||
|
|
||||||
conf = conf._replace(conn_instance=_create_connection(conf))
|
conf = conf._replace(conn_instance=_create_connection(conf))
|
||||||
@ -770,47 +762,51 @@ def _main():
|
|||||||
"""
|
"""
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument('cmd',
|
||||||
'cmd', choices=COMMANDS.keys(), type=str, help='Operation')
|
choices=COMMANDS.keys(),
|
||||||
|
type=str,
|
||||||
|
help='Operation')
|
||||||
parser.add_argument('-t', '--target', type=str, help='Target version')
|
parser.add_argument('-t', '--target', type=str, help='Target version')
|
||||||
parser.add_argument(
|
parser.add_argument('-c',
|
||||||
'-c', '--conn', type=str, help='Postgresql connection string')
|
'--conn',
|
||||||
parser.add_argument(
|
type=str,
|
||||||
'-d', '--base_dir', type=str, default='', help='Migrations base dir')
|
help='Postgresql connection string')
|
||||||
parser.add_argument(
|
parser.add_argument('-d',
|
||||||
'-u',
|
'--base_dir',
|
||||||
'--user',
|
type=str,
|
||||||
type=str,
|
default='',
|
||||||
help='Override database user in migration info')
|
help='Migrations base dir')
|
||||||
|
parser.add_argument('-u',
|
||||||
|
'--user',
|
||||||
|
type=str,
|
||||||
|
help='Override database user in migration info')
|
||||||
parser.add_argument('-b', '--baseline', type=int, help='Baseline version')
|
parser.add_argument('-b', '--baseline', type=int, help='Baseline version')
|
||||||
parser.add_argument(
|
parser.add_argument('-a',
|
||||||
'-a',
|
'--callbacks',
|
||||||
'--callbacks',
|
type=str,
|
||||||
type=str,
|
help='Comma-separated list of callbacks '
|
||||||
help='Comma-separated list of callbacks '
|
'(type:dir/file)')
|
||||||
'(type:dir/file)')
|
parser.add_argument('-s',
|
||||||
parser.add_argument(
|
'--session',
|
||||||
'-s',
|
action='append',
|
||||||
'--session',
|
help='Session setup (e.g. isolation level)')
|
||||||
action='append',
|
parser.add_argument('-n',
|
||||||
help='Session setup (e.g. isolation level)')
|
'--dryrun',
|
||||||
parser.add_argument(
|
action='store_true',
|
||||||
'-n',
|
help='Say "rollback" in the end instead of "commit"')
|
||||||
'--dryrun',
|
parser.add_argument('-l',
|
||||||
action='store_true',
|
'--termination_interval',
|
||||||
help='Say "rollback" in the end instead of "commit"')
|
type=float,
|
||||||
parser.add_argument(
|
help='Inverval for terminating blocking pids')
|
||||||
'-l',
|
parser.add_argument('-v',
|
||||||
'--termination_interval',
|
'--verbose',
|
||||||
type=float,
|
default=0,
|
||||||
help='Inverval for terminating blocking pids')
|
action='count',
|
||||||
parser.add_argument(
|
help='Be verbose')
|
||||||
'-v', '--verbose', default=0, action='count', help='Be verbose')
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
logging.basicConfig(
|
logging.basicConfig(level=(logging.ERROR - 10 * (min(3, args.verbose))),
|
||||||
level=(logging.ERROR - 10 * (min(3, args.verbose))),
|
format='%(asctime)s %(levelname)-8s: %(message)s')
|
||||||
format='%(asctime)s %(levelname)-8s: %(message)s')
|
|
||||||
|
|
||||||
config = get_config(args.base_dir, args)
|
config = get_config(args.base_dir, args)
|
||||||
|
|
||||||
|
@ -5,6 +5,8 @@ set -e
|
|||||||
chown -R postgres:postgres /dist
|
chown -R postgres:postgres /dist
|
||||||
mkdir -p /var/log/pogsgresql
|
mkdir -p /var/log/pogsgresql
|
||||||
chown postgres:postgres /var/log/pogsgresql
|
chown postgres:postgres /var/log/pogsgresql
|
||||||
sudo -u postgres /usr/lib/postgresql/${PG_MAJOR}/bin/pg_ctl -D /etc/postgresql/10/main -l /var/log/pogsgresql/postgresql-${PG_MAJOR}-main.log start
|
sudo -u postgres /usr/lib/postgresql/${PG_MAJOR}/bin/pg_ctl -D \
|
||||||
|
/etc/postgresql/${PG_MAJOR}/main -l \
|
||||||
|
/var/log/pogsgresql/postgresql-${PG_MAJOR}-main.log start
|
||||||
cd /dist
|
cd /dist
|
||||||
sudo -u postgres -i tox -c /dist/tox.ini
|
sudo -u postgres -i tox -c /dist/tox.ini
|
||||||
|
30
setup.py
30
setup.py
@ -30,32 +30,30 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from distutils import setup
|
from distutils import setup
|
||||||
|
|
||||||
|
|
||||||
REQUIREMENTS = [
|
REQUIREMENTS = [
|
||||||
'sqlparse >= 0.2.1',
|
'sqlparse >= 0.3.0',
|
||||||
'psycopg2 >= 2.6.2',
|
'psycopg2 >= 2.8.2',
|
||||||
'PyYAML >= 3.12'
|
'PyYAML >= 5.1',
|
||||||
]
|
]
|
||||||
|
|
||||||
if sys.version_info < (3, 0):
|
if sys.version_info < (3, 0):
|
||||||
REQUIREMENTS.append('future >= 0.15.2')
|
REQUIREMENTS.append('future >= 0.17.1')
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="yandex-pgmigrate",
|
name='yandex-pgmigrate',
|
||||||
version="1.0.3",
|
version='1.0.3',
|
||||||
description="PostgreSQL migrations made easy",
|
description='PostgreSQL migrations made easy',
|
||||||
license="PostgreSQL License",
|
license='PostgreSQL License',
|
||||||
url="https://github.com/yandex/pgmigrate/",
|
url='https://github.com/yandex/pgmigrate/',
|
||||||
author='Yandex LLC',
|
author='Yandex LLC',
|
||||||
author_email='opensource@yandex-team.ru',
|
author_email='opensource@yandex-team.ru',
|
||||||
maintainer='Yandex LLC',
|
maintainer='Yandex LLC',
|
||||||
maintainer_email='opensource@yandex-team.ru',
|
maintainer_email='opensource@yandex-team.ru',
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
platforms=["Linux", "BSD", "MacOS"],
|
platforms=['Linux', 'BSD', 'MacOS'],
|
||||||
packages=['.'],
|
packages=['.'],
|
||||||
entry_points={
|
entry_points={'console_scripts': [
|
||||||
'console_scripts': [
|
'pgmigrate = pgmigrate:_main',
|
||||||
'pgmigrate = pgmigrate:_main',
|
]},
|
||||||
]},
|
|
||||||
install_requires=REQUIREMENTS,
|
install_requires=REQUIREMENTS,
|
||||||
)
|
)
|
||||||
|
4
tox.ini
4
tox.ini
@ -48,9 +48,9 @@ deps = pylint
|
|||||||
|
|
||||||
[testenv:yapf]
|
[testenv:yapf]
|
||||||
commands = yapf -pd pgmigrate.py
|
commands = yapf -pd pgmigrate.py
|
||||||
deps = yapf==0.22.0
|
deps = yapf==0.27.0
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
copyright-check = True
|
copyright-check = True
|
||||||
copyright-regexp = Copyright\s+(\(C\)\s+)?(\d{4}-)?2016-2018\s+%(author)s
|
copyright-regexp = Copyright\s+(\(C\)\s+)?(\d{4}-)?2016-2019\s+%(author)s
|
||||||
copyright-author = Yandex LLC
|
copyright-author = Yandex LLC
|
||||||
|
Loading…
Reference in New Issue
Block a user