Added logic to skip migrations for sqlite databases, as sqlite does not support altering

schema data.

Added non-py Alembic files to packaging process, as they must be present for
migration sprocessing to success in deployed environments.

Modified the version stamping script to stamp versions without need for templated fields to
be preserved, allowing for repeated calls to update scripts automatically. This is
especially useful for development purposes.

Change-Id: I98af79fee8fec3ac131e54035d00ce0a8f855a63
This commit is contained in:
John Wood 2013-07-08 18:18:48 -05:00
parent 0517c90a68
commit 03d59136f3
2 changed files with 36 additions and 28 deletions

View File

@ -27,29 +27,38 @@ CONF.register_opts(db_opts)
def init_config(sql_url=None):
"""Initialize and return the Alembic configuration."""
sqlalchemy_url = sql_url or CONF.sql_connection
if 'sqlite' in sqlalchemy_url:
LOG.warn('!!! No support for migrating sqlite databases...'
'skipping migration processing !!!')
return None
config = alembic_config.Config(
os.path.join(os.path.dirname(__file__), 'alembic.ini')
)
config.barbican_sqlalchemy_url = sqlalchemy_url
config.set_main_option('script_location',
'barbican.model.migration:alembic_migrations')
config.barbican_sqlalchemy_url = sql_url or CONF.sql_connection
return config
def upgrade(to_version='head', sql_url=None):
"""Upgrade to the specified version."""
alembic_cfg = init_config(sql_url)
alembic_command.upgrade(alembic_cfg, to_version)
if alembic_cfg:
alembic_command.upgrade(alembic_cfg, to_version)
def downgrade(to_version, sql_url=None):
"""Downgrade to the specified version."""
alembic_cfg = init_config(sql_url)
alembic_command.downgrade(alembic_cfg, to_version)
if alembic_cfg:
alembic_command.downgrade(alembic_cfg, to_version)
def generate(autogenerate=True, message='generate changes', sql_url=None):
"""Generate a version file."""
alembic_cfg = init_config(sql_url)
alembic_command.revision(alembic_cfg, message=message,
autogenerate=autogenerate)
if alembic_cfg:
alembic_command.revision(alembic_cfg, message=message,
autogenerate=autogenerate)

View File

@ -19,7 +19,7 @@
# under the License.
"""
Product a release version of this build (by removing the 'dev' suffix)
Product a release version of this build
"""
import os
@ -32,7 +32,7 @@ from time import strftime, gmtime
PKG = "barbican"
VERSIONFILE = os.path.join(PKG, "version.py")
CHANGEFILE = os.path.join("debian", "changelog")
SIMPLEFILE = 'versiononly.txt'
SIMPLEFILE = 'versiononly.txt'
current_dir = os.getcwd()
if current_dir.endswith('bin'):
VERSIONFILE = os.path.join("..", PKG, "version.py")
@ -42,7 +42,7 @@ if current_dir.endswith('bin'):
def get_version():
"""Retrieves the current version string from the version.py file"""
version = "unknown"
try:
try:
version_file = open(VERSIONFILE, "r")
for line in version_file:
if line.startswith('__version__'):
@ -73,11 +73,16 @@ def get_commit_id():
def format_release_version(version, build_id_to_inject):
"""Injects the specified build id into the version string."""
return version.format(build_id=build_id_to_inject)
"""
Injects the specified build id into the build section of the version string.
The build section is the third group after the second '.'.
"""
subs = version.split(".")
subs[2] = build_id_to_inject
return '.'.join(subs)
def format_build_id_as_datetime():
def generate_build_id_as_datetime():
return strftime("%Y%m%d%H%M%S", gmtime())
@ -108,15 +113,18 @@ def update_changefile(version):
try:
with open(CHANGEFILE, 'r') as file_old:
for line in file_old:
if '{version}' in line:
new_version_line = line.format(version=version)
file_new.write(new_version_line)
elif '{datetime}' in line:
line_new = ''
if line.startswith(PKG):
left = line[:line.index('(') + 1]
right = line[line.index('-1)'):]
line_new = ''.join([left, version, right])
elif '--' in line:
left = line[:line.index('>') + 1]
now_text = strftime("%a, %d %b %Y %H:%M:%S %z")
new_commiter_line = line.format(datetime=now_text)
file_new.write(new_commiter_line)
line_new = ''.join([left, ' ', now_text])
else:
file_new.write(line)
line_new = line
file_new.write(line_new)
finally:
file_new.close()
os.rename(temp_name, CHANGEFILE)
@ -130,7 +138,7 @@ if __name__ == '__main__':
# Create a release version and update the version.py file accordingly.
commit_short, commit_long = get_commit_id()
release = format_release_version(version,
format_build_id_as_datetime())
generate_build_id_as_datetime())
print 'release: ', release
print 'commit (long): ', commit_long
print 'commit (short): ', commit_short
@ -141,12 +149,3 @@ if __name__ == '__main__':
# Output the version number to a flat file.
with open(SIMPLEFILE, 'w') as outver:
outver.write(release)