"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "linotpd/src/linotp/model/migrate.py" between
LinOTP-release-2.11.2.tar.gz and LinOTP-release-2.12.tar.gz

About: LinOTP is a flexible and versatile OTP-platform for strong user authentication (two-factor authentication with one time passwords).

migrate.py  (LinOTP-release-2.11.2):migrate.py  (LinOTP-release-2.12)
skipping to change at line 69 skipping to change at line 69
# #
# get the list of all columns with their description as dict # get the list of all columns with their description as dict
columns = insp.get_columns(table_name) columns = insp.get_columns(table_name)
for column_item in columns: for column_item in columns:
if column_item.get('name') == column.name: if column_item.get('name') == column.name:
return True return True
return False return False
def _compile_name(name, dialect):
"""
helper - to adjust the names of table / column / index to quoted or not
in postgresql the tablenames / column /index names must be quotes
while not so in mysql
:param name: tablename, index name of column name
:param engine: the corresponding engine for mysql / postgresql
:return: the adjusted name
"""
return sa.Column(name, sa.types.Integer()).compile(dialect=dialect)
def add_column(engine, table_name, column): def add_column(engine, table_name, column):
""" """
create an index based on the column index definition create an index based on the column index definition
calling the compiled SQL statement: calling the compiled SQL statement:
ALTER TABLE table_name ADD COLUMN column_name column_type ALTER TABLE table_name ADD COLUMN column_name column_type
:param engine: the bound sql database engine :param engine: the bound sql database engine
:param table_name: the name of the table with the column :param table_name: the name of the table with the column
:param column: the instantiated column defintion :param column: the instantiated column defintion
:return: - nothing - :return: - nothing -
""" """
column_name = column.compile(dialect=engine.dialect)
column_type = column.type.compile(engine.dialect) c_table_name = _compile_name(table_name, dialect=engine.dialect)
c_column_name = column.compile(dialect=engine.dialect)
c_column_type = column.type.compile(engine.dialect)
engine.execute('ALTER TABLE %s ADD COLUMN %s %s' % engine.execute('ALTER TABLE %s ADD COLUMN %s %s' %
(table_name, column_name, column_type)) (c_table_name, c_column_name, c_column_type))
def add_index(engine,table_name, index, column): def add_index(engine, table_name, index, column):
""" """
create an index based on the column index definition create an index based on the column index definition
calling the compiled SQL statement: calling the compiled SQL statement:
CREATE INDEX index_name CREATE INDEX index_name
ON table_name (column_name) ON table_name (column_name)
:param engine: the bound sql database engine :param engine: the bound sql database engine
:param index: the name of the index - string :param index: the name of the index - string
:param table_name: the name of the table with the column :param table_name: the name of the table with the column
:param column: the instantiated column defintion :param column: the instantiated column definition
:return: - nothing - :return: - nothing -
""" """
column_name = column.compile(dialect=engine.dialect) c_table_name = _compile_name(table_name, dialect=engine.dialect)
column_index = "ix_%s_%s" % (table_name, column_name)
c_column_name = column.compile(dialect=engine.dialect)
index_name = "ix_%s_%s" % (table_name, column.name)
c_index_name = _compile_name(index_name, dialect=engine.dialect)
engine.execute('CREATE INDEX %s ON %s ( %s )' % engine.execute('CREATE INDEX %s ON %s ( %s )' %
(column_index, table_name, column_name)) (c_index_name, c_table_name, c_column_name))
def drop_column(engine, table_name, column): def drop_column(engine, table_name, column):
""" """
calling the compiled SQL statement calling the compiled SQL statement
ALTER TABLE table_name drop COLUMN column ALTER TABLE table_name drop COLUMN column
:param engine: the bound sql database engine :param engine: the bound sql database engine
:param table_name: the name of the table with the column :param table_name: the name of the table with the column
:param column: the instantiated column defintion :param column: the instantiated column defintion
:return: - nothing - :return: - nothing -
""" """
column_name = column.compile(dialect=engine.dialect) c_table_name = _compile_name(table_name, dialect=engine.dialect)
c_column_name = column.compile(dialect=engine.dialect)
engine.execute('ALTER TABLE %s drop COLUMN %s ' % engine.execute('ALTER TABLE %s drop COLUMN %s ' %
(table_name, column_name)) (c_table_name, c_column_name))
def run_data_model_migration(meta): def run_data_model_migration(meta):
""" """
hook for database schema upgrade hook for database schema upgrade
- called by paster setup-app or on the first request to linotp - called by paster setup-app or on the first request to linotp
""" """
# define the most recent target version # define the most recent target version
target_version = "2.10.1.0" target_version = "2.12.0.0"
migration = Migration(meta) migration = Migration(meta)
# start with the current version, which is retreived from the db # start with the current version, which is retrieved from the db
current_version = migration.get_current_version() current_version = migration.get_current_version()
# run the steps in the migration chain # run the steps in the migration chain
migration.migrate(from_version=current_version, to_version=target_version) migration.migrate(from_version=current_version, to_version=target_version)
# finally set the target version we reached # finally set the target version we reached
migration.set_version(target_version) migration.set_version(target_version)
return target_version return target_version
skipping to change at line 172 skipping to change at line 196
# model version key in the config table # model version key in the config table
db_model_key = u'linotp.sql_data_model_version' db_model_key = u'linotp.sql_data_model_version'
# define the chain of migration steps starting with the not existing one # define the chain of migration steps starting with the not existing one
migration_steps = [ migration_steps = [
None, None,
"2.9.1.0", "2.9.1.0",
"2.10.1.0" "2.10.1.0",
"2.12.0.0",
] ]
def __init__(self, meta): def __init__(self, meta):
""" """
class init class init
- preserve the database handle - preserve the database handle
""" """
self.meta = meta self.meta = meta
self.current_version = None self.current_version = None
skipping to change at line 327 skipping to change at line 352
if not has_column(self.meta, challenge_table, bchallenges): if not has_column(self.meta, challenge_table, bchallenges):
add_column(self.meta.engine, challenge_table, bchallenges) add_column(self.meta.engine, challenge_table, bchallenges)
# add new blob data column # add new blob data column
bdata = sa.Column('bdata', sa.types.Binary()) bdata = sa.Column('bdata', sa.types.Binary())
if not has_column(self.meta, challenge_table, bdata): if not has_column(self.meta, challenge_table, bdata):
add_column(self.meta.engine, challenge_table, bdata) add_column(self.meta.engine, challenge_table, bdata)
# migration towards 2.12.
def migrate_2_12_0_0(self):
"""
run the migration for token to add the time stamps for
created, accessed and verified
"""
token_table = "Token"
# add created column to tokens
created = sa.Column('LinOtpCreationDate', sa.types.DateTime, index=True)
if not has_column(self.meta, token_table, created):
add_column(self.meta.engine, token_table, created)
add_index(self.meta.engine, token_table, 'LinOtpCreationDate', creat
ed)
# add verified column to tokens
verified = sa.Column('LinOtpLastAuthSuccess', sa.types.DateTime, index=T
rue)
if not has_column(self.meta, token_table, verified):
add_column(self.meta.engine, token_table, verified)
add_index(self.meta.engine, token_table, 'LinOtpLastAuthSuccess', ve
rified)
# add accessed column to tokens
accessed = sa.Column('LinOtpLastAuthMatch', sa.types.DateTime, index=Tru
e)
if not has_column(self.meta, token_table, accessed):
add_column(self.meta.engine, token_table, accessed)
add_index(self.meta.engine, token_table, 'LinOtpLastAuthMatch', acce
ssed)
# eof # eof
 End of changes. 13 change blocks. 
13 lines changed or deleted 74 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)