Python alembic.op.execute() Examples
The following are 30
code examples of alembic.op.execute().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
alembic.op
, or try the search function
.
Example #1
Source File: e445d703e60f_removing_partitions_adding_foreign_keys.py From cloud-inquisitor with Apache License 2.0 | 6 votes |
def upgrade(): partitions = ( 'tags', 'resources', 'resource_properties', 'issues', 'issue_properties', 'auditlog', 'logs', 'emails' ) for table in partitions: try: op.execute('ALTER TABLE `{}` REMOVE PARTITIONING'.format(table)) except SQLAlchemyError as ex: # Silently ignore errors about removing partitions from a table without partitions if str(ex).find('1505') != -1: pass raise # ### commands auto generated by Alembic - please adjust! ### op.create_foreign_key('fk_resource_mapping_child', 'resource_mappings', 'resources', ['child'], ['resource_id'], ondelete='CASCADE') op.create_foreign_key('fk_resource_mapping_parent', 'resource_mappings', 'resources', ['parent'], ['resource_id'], ondelete='CASCADE') op.create_foreign_key('fk_resource_property_resource_id', 'resource_properties', 'resources', ['resource_id'], ['resource_id'], ondelete='CASCADE') op.create_foreign_key('fk_resource_account_id', 'resources', 'accounts', ['account_id'], ['account_id'], ondelete='CASCADE') op.create_foreign_key('fk_resource_types_resource_type_id', 'resources', 'resource_types', ['resource_type_id'], ['resource_type_id'], ondelete='CASCADE') op.create_foreign_key('fk_tag_resource_id', 'tags', 'resources', ['resource_id'], ['resource_id'], ondelete='CASCADE') # ### end Alembic commands ###
Example #2
Source File: 644ef887bb6f_add_close_status.py From pagure with GNU General Public License v2.0 | 6 votes |
def downgrade(): ''' Add the column _close_status to the table projects. ''' engine = op.get_bind() Session = sa.orm.scoped_session(sa.orm.sessionmaker()) Session.configure(bind=engine) session = Session() statuses = ['Invalid', 'Insufficient data', 'Fixed', 'Duplicate'] for status in statuses: ticket_stat = model.StatusIssue(status=status) session.add(ticket_stat) session.commit() # Set the close_status for all the closed tickets op.execute('''UPDATE "issues" SET status=close_status where status != 'Open'; ''') # Remove the old status op.execute('''DELETE FROM "status_issue" WHERE status = 'Closed'; ''') op.drop_column('projects', '_close_status') op.drop_column('issues', 'close_status')
Example #3
Source File: aba5a217ca9b_merge_created_in_creator.py From gnocchi with Apache License 2.0 | 6 votes |
def upgrade(): for table_name in ("resource", "resource_history", "metric"): creator_col = sa.Column("creator", sa.String(255)) created_by_user_id_col = sa.Column("created_by_user_id", sa.String(255)) created_by_project_id_col = sa.Column("created_by_project_id", sa.String(255)) op.add_column(table_name, creator_col) t = sa.sql.table( table_name, creator_col, created_by_user_id_col, created_by_project_id_col) op.execute( t.update().values( creator=( created_by_user_id_col + ":" + created_by_project_id_col )).where((created_by_user_id_col is not None) | (created_by_project_id_col is not None))) op.drop_column(table_name, "created_by_user_id") op.drop_column(table_name, "created_by_project_id")
Example #4
Source File: d4db9d4eff92_.py From comport with BSD 3-Clause "New" or "Revised" License | 6 votes |
def upgrade(): op.rename_table('use_of_force_incidents', 'use_of_force_incidents_impd') op.execute('ALTER SEQUENCE use_of_force_incidents_id_seq RENAME TO use_of_force_incidents_impd_id_seq') op.execute('ALTER INDEX use_of_force_incidents_pkey RENAME TO use_of_force_incidents_impd_pkey') op.execute('ALTER TABLE use_of_force_incidents_impd RENAME CONSTRAINT "use_of_force_incidents_department_id_fkey" TO "use_of_force_incidents_impd_department_id_fkey"') op.rename_table('citizen_complaints', 'citizen_complaints_impd') op.execute('ALTER SEQUENCE citizen_complaints_id_seq RENAME TO citizen_complaints_impd_id_seq') op.execute('ALTER INDEX citizen_complaints_pkey RENAME TO citizen_complaints_impd_pkey') op.execute('ALTER TABLE citizen_complaints_impd RENAME CONSTRAINT "citizen_complaints_department_id_fkey" TO "citizen_complaints_impd_department_id_fkey"') op.rename_table('assaults_on_officers', 'assaults_on_officers_impd') op.execute('ALTER SEQUENCE assaults_on_officers_id_seq RENAME TO assaults_on_officers_impd_id_seq') op.execute('ALTER INDEX assaults_on_officers_pkey RENAME TO assaults_on_officers_impd_pkey') op.execute('ALTER TABLE assaults_on_officers_impd RENAME CONSTRAINT "assaults_on_officers_department_id_fkey" TO "assaults_on_officers_impd_department_id_fkey"') op.rename_table('officer_involved_shootings', 'officer_involved_shootings_impd') op.execute('ALTER SEQUENCE officer_involved_shootings_id_seq RENAME TO officer_involved_shootings_impd_id_seq') op.execute('ALTER INDEX officer_involved_shootings_pkey RENAME TO officer_involved_shootings_impd_pkey') op.execute('ALTER TABLE officer_involved_shootings_impd RENAME CONSTRAINT "officer_involved_shootings_department_id_fkey" TO "officer_involved_shootings_impd_department_id_fkey"')
Example #5
Source File: 1d18843a1994_add_is_fork_column_to_projects.py From pagure with GNU General Public License v2.0 | 6 votes |
def upgrade(): ''' Add is_fork column to project table''' op.add_column( 'projects', sa.Column( 'is_fork', sa.Boolean, default=False, nullable=True) ) op.execute('''UPDATE "projects" ''' '''SET is_fork=TRUE WHERE parent_id IS NOT NULL;''') op.execute('''UPDATE "projects" ''' '''SET is_fork=FALSE WHERE parent_id IS NULL;''') op.alter_column( 'projects', 'is_fork', nullable=False, existing_nullable=True)
Example #6
Source File: 7f31a9fad89f_expand_enum_for_lock_types.py From pagure with GNU General Public License v2.0 | 6 votes |
def upgrade(): """ Add new lock types to the lock_type_enum enum. With this there are three enums: - WORKER, used to lock action on the main git repo (sources) - WORKER_TICKET, used to lock actions on the ticket git repo - WORKER_REQUEST, used to lock actions on the request git repo """ # Let's start with commit to close the current transaction # cf https://bitbucket.org/zzzeek/alembic/issue/123 op.execute('COMMIT') op.execute( "ALTER TYPE lock_type_enum ADD VALUE 'WORKER_TICKET';") op.execute( "ALTER TYPE lock_type_enum ADD VALUE 'WORKER_REQUEST';")
Example #7
Source File: 298891e63039_change_the_status_of_pull_requests.py From pagure with GNU General Public License v2.0 | 6 votes |
def downgrade(): ''' Revert the status column of the pull_requests table. ''' op.add_column( 'pull_requests', sa.Column( '_status', sa.Boolean, default=True, nullable=True) ) op.execute('''UPDATE "pull_requests" ''' '''SET _status=TRUE WHERE status='Open';''') op.execute('''UPDATE "pull_requests" ''' '''SET _status=FALSE WHERE status!='Open';''') op.drop_column('pull_requests', 'status') op.alter_column( 'pull_requests', column_name='_status', new_column_name='status', nullable=False, existing_nullable=True)
Example #8
Source File: 6190226bed0_add_the_updated_on_column_to_pull_.py From pagure with GNU General Public License v2.0 | 6 votes |
def upgrade(): ''' Add the column updated_on to the table pull_requests. ''' op.add_column( 'pull_requests', sa.Column( 'updated_on', sa.DateTime, nullable=True, default=sa.func.now(), onupdate=sa.func.now() ) ) op.execute('''UPDATE "pull_requests" SET updated_on=date_created;''') op.alter_column( 'pull_requests', column_name='updated_on', nullable=False, existing_nullable=True)
Example #9
Source File: 6119fbbcc8e9_migrate_current_flag.py From pagure with GNU General Public License v2.0 | 6 votes |
def upgrade(): """ Add the status column to pull_request_flags and migrate the data. """ op.add_column( 'pull_request_flags', sa.Column('status', sa.String(32), nullable=True) ) op.execute( 'UPDATE pull_request_flags SET status=\'success\' ' 'WHERE percent in (100, \'100\')') op.execute( 'UPDATE pull_request_flags SET status=\'failure\' ' 'WHERE percent not in (100, \'100\')') op.alter_column( 'pull_request_flags', 'status', nullable=False, existing_nullable=True)
Example #10
Source File: e18d5b78d782_add_ci_job_attribute_to_the_hook_pagure_.py From pagure with GNU General Public License v2.0 | 6 votes |
def upgrade(): ''' Add ci_job column to projects table''' op.add_column( 'hook_pagure_ci', sa.Column('ci_job', sa.String(255), nullable=True, unique=False) ) con = op.get_bind() results = con.execute('SELECT id, ci_url FROM hook_pagure_ci') for id, url in results: ci_job = url.split('/job/', 1)[1].split('/', 1)[0] ci_url = url.split('/job/')[0] op.execute( "UPDATE hook_pagure_ci SET ci_job='{}' WHERE id = '{}'".format(ci_job, id)) op.execute( "UPDATE hook_pagure_ci SET ci_url='{}' WHERE id = '{}'".format(ci_url, id)) op.alter_column( 'hook_pagure_ci', 'ci_job', nullable=False, existing_nullable=True)
Example #11
Source File: 21d6b9dc9961_add_mismatch_scheme_state_to_requests.py From rucio with Apache License 2.0 | 6 votes |
def upgrade(): ''' Upgrade the database to this revision ''' schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else '' if context.get_context().dialect.name in ['oracle', 'postgresql']: drop_constraint('REQUESTS_STATE_CHK', 'requests', type_='check') create_check_constraint(constraint_name='REQUESTS_STATE_CHK', table_name='requests', condition="state in ('Q', 'G', 'S', 'D', 'F', 'L', 'N', 'O', 'A', 'U', 'W', 'M')") elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 5: create_check_constraint(constraint_name='REQUESTS_STATE_CHK', table_name='requests', condition="state in ('Q', 'G', 'S', 'D', 'F', 'L', 'N', 'O', 'A', 'U', 'W', 'M')") elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 8: op.execute('ALTER TABLE ' + schema + 'requests DROP CHECK REQUESTS_STATE_CHK') # pylint: disable=no-member create_check_constraint(constraint_name='REQUESTS_STATE_CHK', table_name='requests', condition="state in ('Q', 'G', 'S', 'D', 'F', 'L', 'N', 'O', 'A', 'U', 'W', 'M')")
Example #12
Source File: 45378a1e76a8_create_collection_replica_table.py From rucio with Apache License 2.0 | 6 votes |
def downgrade(): ''' Downgrade the database to the previous revision ''' if context.get_context().dialect.name == 'oracle': drop_constraint('COLLECTION_REPLICAS_STATE_CHK', 'collection_replicas', type_='check') drop_table('collection_replicas') elif context.get_context().dialect.name == 'postgresql': schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else '' op.execute('ALTER TABLE ' + schema + 'collection_replicas ALTER COLUMN state TYPE CHAR') # pylint: disable=no-member drop_constraint('COLLECTION_REPLICAS_STATE_CHK', 'collection_replicas', type_='check') drop_table('collection_replicas') elif context.get_context().dialect.name == 'mysql': drop_table('collection_replicas')
Example #13
Source File: 1d96f484df21_asynchronous_rules_and_rule_approval.py From rucio with Apache License 2.0 | 6 votes |
def downgrade(): ''' Downgrade the database to the previous revision ''' schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else '' if context.get_context().dialect.name == 'oracle': drop_column('rules', 'ignore_account_limit') drop_constraint('RULES_STATE_CHK', 'rules') create_check_constraint('RULES_STATE_CHK', 'rules', "state IN ('S', 'R', 'U', 'O')") elif context.get_context().dialect.name == 'postgresql': drop_column('rules', 'ignore_account_limit', schema=schema[:-1]) op.execute('ALTER TABLE ' + schema + 'rules DROP CONSTRAINT IF EXISTS "RULES_STATE_CHK", ALTER COLUMN state TYPE CHAR') # pylint: disable=no-member create_check_constraint('RULES_STATE_CHK', 'rules', "state IN ('S', 'R', 'U', 'O')") elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 5: drop_column('rules', 'ignore_account_limit', schema=schema[:-1]) create_check_constraint('RULES_STATE_CHK', 'rules', "state IN ('S', 'R', 'U', 'O')") elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 8: drop_column('rules', 'ignore_account_limit', schema=schema[:-1]) op.execute('ALTER TABLE ' + schema + 'rules DROP CHECK RULES_STATE_CHK') # pylint: disable=no-member create_check_constraint('RULES_STATE_CHK', 'rules', "state IN ('S', 'R', 'U', 'O')")
Example #14
Source File: d4db9d4eff92_.py From comport with BSD 3-Clause "New" or "Revised" License | 6 votes |
def downgrade(): op.rename_table('use_of_force_incidents_impd', 'use_of_force_incidents') op.execute('ALTER SEQUENCE use_of_force_incidents_impd_id_seq RENAME TO use_of_force_incidents_id_seq') op.execute('ALTER INDEX use_of_force_incidents_impd_pkey RENAME TO use_of_force_incidents_pkey') op.execute('ALTER TABLE use_of_force_incidents RENAME CONSTRAINT "use_of_force_incidents_impd_department_id_fkey" TO "use_of_force_incidents_department_id_fkey"') op.rename_table('citizen_complaints_impd', 'citizen_complaints') op.execute('ALTER SEQUENCE citizen_complaints_impd_id_seq RENAME TO citizen_complaints_id_seq') op.execute('ALTER INDEX citizen_complaints_impd_pkey RENAME TO citizen_complaints_pkey') op.execute('ALTER TABLE citizen_complaints RENAME CONSTRAINT "citizen_complaints_impd_department_id_fkey" TO "citizen_complaints_department_id_fkey"') op.rename_table('assaults_on_officers_impd', 'assaults_on_officers') op.execute('ALTER SEQUENCE assaults_on_officers_impd_id_seq RENAME TO assaults_on_officers_id_seq') op.execute('ALTER INDEX assaults_on_officers_impd_pkey RENAME TO assaults_on_officers_pkey') op.execute('ALTER TABLE assaults_on_officers RENAME CONSTRAINT "assaults_on_officers_impd_department_id_fkey" TO "assaults_on_officers_department_id_fkey"') op.rename_table('officer_involved_shootings_impd', 'officer_involved_shootings') op.execute('ALTER SEQUENCE officer_involved_shootings_impd_id_seq RENAME TO officer_involved_shootings_id_seq') op.execute('ALTER INDEX officer_involved_shootings_impd_pkey RENAME TO officer_involved_shootings_pkey') op.execute('ALTER TABLE officer_involved_shootings RENAME CONSTRAINT "officer_involved_shootings_impd_department_id_fkey" TO "officer_involved_shootings_department_id_fkey"')
Example #15
Source File: 1176fec745c0_.py From SempoBlockchain with GNU General Public License v3.0 | 6 votes |
def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.add_column('credit_transfer', sa.Column('transfer_metadata', postgresql.JSONB(astext_type=sa.Text()), nullable=True)) # Create a tempoary "_status" type, convert and drop the "old" type tmp_type.create(op.get_bind(), checkfirst=False) op.execute('ALTER TABLE credit_transfer ALTER COLUMN transfer_type TYPE _transfertypeenum' ' USING transfer_type::text::_transfertypeenum') # Convert 'DISBURSEMENT' transfer_type into 'DEPOSIT' op.execute(tcr.update().where(tcr.c.transfer_type == u'DISBURSEMENT').values(transfer_type='DEPOSIT')) old_type.drop(op.get_bind(), checkfirst=False) # Create and convert to the "new" status type new_type.create(op.get_bind(), checkfirst=False) op.execute('ALTER TABLE credit_transfer ALTER COLUMN transfer_type TYPE transfertypeenum' ' USING transfer_type::text::transfertypeenum') tmp_type.drop(op.get_bind(), checkfirst=False) # ### end Alembic commands ###
Example #16
Source File: c9a8d520a26_schema_v9.py From king-phisher with BSD 3-Clause "New" or "Revised" License | 6 votes |
def upgrade(): op.add_column('campaigns', sqlalchemy.Column('credential_regex_username', sqlalchemy.String)) op.add_column('campaigns', sqlalchemy.Column('credential_regex_password', sqlalchemy.String)) op.add_column('campaigns', sqlalchemy.Column('credential_regex_mfa_token', sqlalchemy.String)) op.add_column('credentials', sqlalchemy.Column('mfa_token', sqlalchemy.String)) op.add_column('credentials', sqlalchemy.Column('regex_validated', sqlalchemy.Boolean)) op.add_column('users', sqlalchemy.Column('access_level', sqlalchemy.Integer)) op.execute('UPDATE users SET access_level = 1000') op.alter_column('users', 'access_level', nullable=False) # adjust the schema version metadata db_manager.Session.remove() db_manager.Session.configure(bind=op.get_bind()) session = db_manager.Session() db_manager.set_metadata('schema_version', 9, session=session) session.commit()
Example #17
Source File: 00044_7dd0f20f06d4_can_we_add_autoincrement.py From ReadableWebProxy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def upgrade(): op.execute("""CREATE SEQUENCE raw_web_pages_version_transaction_id_seq OWNED BY raw_web_pages_version.transaction_id;""") op.execute("""SELECT setval('raw_web_pages_version_transaction_id_seq', (SELECT max(transaction_id) FROM raw_web_pages_version));""") op.execute("""ALTER TABLE raw_web_pages_version ALTER COLUMN transaction_id SET DEFAULT nextval('raw_web_pages_version_transaction_id_seq');""") op.execute("""CREATE SEQUENCE web_pages_version_transaction_id_seq OWNED BY web_pages_version.transaction_id;""") op.execute("""SELECT setval('web_pages_version_transaction_id_seq', (SELECT max(transaction_id) FROM web_pages_version));""") op.execute("""ALTER TABLE web_pages_version ALTER COLUMN transaction_id SET DEFAULT nextval('web_pages_version_transaction_id_seq');""") op.execute("""CREATE SEQUENCE rss_parser_feed_name_lut_version_transaction_id_seq OWNED BY rss_parser_feed_name_lut_version.transaction_id;""") op.execute("""SELECT setval('rss_parser_feed_name_lut_version_transaction_id_seq', (SELECT max(transaction_id) FROM rss_parser_feed_name_lut_version));""") op.execute("""ALTER TABLE rss_parser_feed_name_lut_version ALTER COLUMN transaction_id SET DEFAULT nextval('rss_parser_feed_name_lut_version_transaction_id_seq');""") op.execute("""CREATE SEQUENCE rss_parser_funcs_version_transaction_id_seq OWNED BY rss_parser_funcs_version.transaction_id;""") op.execute("""SELECT setval('rss_parser_funcs_version_transaction_id_seq', (SELECT max(transaction_id) FROM rss_parser_funcs_version));""") op.execute("""ALTER TABLE rss_parser_funcs_version ALTER COLUMN transaction_id SET DEFAULT nextval('rss_parser_funcs_version_transaction_id_seq');""") pass
Example #18
Source File: 01eaf73ab656_add_new_rule_notification_state_progress.py From rucio with Apache License 2.0 | 6 votes |
def upgrade(): ''' Upgrade the database to this revision ''' schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else '' if context.get_context().dialect.name == 'oracle': drop_constraint('RULES_NOTIFICATION_CHK', 'rules', type_='check') create_check_constraint(constraint_name='RULES_NOTIFICATION_CHK', table_name='rules', condition="notification in ('Y', 'N', 'C', 'P')") elif context.get_context().dialect.name == 'postgresql': op.execute('ALTER TABLE ' + schema + 'rules DROP CONSTRAINT IF EXISTS "RULES_NOTIFICATION_CHK", ALTER COLUMN notification TYPE CHAR') # pylint: disable=no-member create_check_constraint(constraint_name='RULES_NOTIFICATION_CHK', table_name='rules', condition="notification in ('Y', 'N', 'C', 'P')") elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 5: create_check_constraint(constraint_name='RULES_NOTIFICATION_CHK', table_name='rules', condition="notification in ('Y', 'N', 'C', 'P')") elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 8: op.execute('ALTER TABLE ' + schema + 'rules DROP CHECK RULES_NOTIFICATION_CHK') # pylint: disable=no-member create_check_constraint(constraint_name='RULES_NOTIFICATION_CHK', table_name='rules', condition="notification in ('Y', 'N', 'C', 'P')")
Example #19
Source File: 9eb936a81eb1_true_is_true.py From rucio with Apache License 2.0 | 6 votes |
def downgrade(): ''' Downgrade the database to the previous revision ''' # First, change all lowercase booleanstrings to uppercase booleanstrings if context.get_context().dialect.name in ['oracle', 'mysql', 'postgresql']: schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else '' op.execute("UPDATE " + schema + "account_attr_map SET value='True' WHERE value='true'") # pylint: disable=no-member op.execute("UPDATE " + schema + "account_attr_map SET value='False' WHERE value='false'") # pylint: disable=no-member op.execute("UPDATE " + schema + "rse_attr_map SET value='True' WHERE value='true'") # pylint: disable=no-member op.execute("UPDATE " + schema + "rse_attr_map SET value='False' WHERE value='false'") # pylint: disable=no-member # Second, change __selected__ true/false to 0/1. This cannot be done # automatically, as we don't know which ones were previously stored as INT. # # Must be done selectively by the operator: # UPDATE account_attr_map SET value='1' WHERE value='true' AND .. # UPDATE account_attr_map SET value='0' WHERE value='false' AND .. # UPDATE rse_attr_map SET value='1' WHERE value='true' AND .. # UPDATE rse_attr_map SET value='0' WHERE value='false' AND ..
Example #20
Source File: 7ec22226cdbf_new_replica_state_for_temporary_.py From rucio with Apache License 2.0 | 6 votes |
def downgrade(): ''' Downgrade the database to the previous revision ''' schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else '' if context.get_context().dialect.name == 'oracle': drop_constraint('REPLICAS_STATE_CHK', 'replicas', type_='check') create_check_constraint(constraint_name='REPLICAS_STATE_CHK', table_name='replicas', condition="state in ('A', 'U', 'C', 'B', 'D', 'S')") elif context.get_context().dialect.name == 'postgresql': op.execute('ALTER TABLE ' + schema + 'replicas DROP CONSTRAINT IF EXISTS "REPLICAS_STATE_CHK", ALTER COLUMN state TYPE CHAR') # pylint: disable=no-member create_check_constraint(constraint_name='REPLICAS_STATE_CHK', table_name='replicas', condition="state in ('A', 'U', 'C', 'B', 'D', 'S')") elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 5: create_check_constraint(constraint_name='REPLICAS_STATE_CHK', table_name='replicas', condition="state in ('A', 'U', 'C', 'B', 'D', 'S')") elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 8: op.execute('ALTER TABLE ' + schema + 'replicas DROP CHECK REPLICAS_STATE_CHK') # pylint: disable=no-member create_check_constraint(constraint_name='REPLICAS_STATE_CHK', table_name='replicas', condition="state in ('A', 'U', 'C', 'B', 'D', 'S')")
Example #21
Source File: 7ec22226cdbf_new_replica_state_for_temporary_.py From rucio with Apache License 2.0 | 6 votes |
def upgrade(): ''' Upgrade the database to this revision ''' schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else '' if context.get_context().dialect.name in ['oracle', 'postgresql']: drop_constraint('REPLICAS_STATE_CHK', 'replicas', type_='check') create_check_constraint(constraint_name='REPLICAS_STATE_CHK', table_name='replicas', condition="state in ('A', 'U', 'C', 'B', 'D', 'S', 'T')") elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 5: create_check_constraint(constraint_name='REPLICAS_STATE_CHK', table_name='replicas', condition="state in ('A', 'U', 'C', 'B', 'D', 'S', 'T')") elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 8: op.execute('ALTER TABLE ' + schema + 'replicas DROP CHECK REPLICAS_STATE_CHK') # pylint: disable=no-member create_check_constraint(constraint_name='REPLICAS_STATE_CHK', table_name='replicas', condition="state in ('A', 'U', 'C', 'B', 'D', 'S', 'T')")
Example #22
Source File: 3c9df354071b_extend_waiting_request_state.py From rucio with Apache License 2.0 | 6 votes |
def downgrade(): ''' Downgrade the database to the previous revision ''' schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else '' if context.get_context().dialect.name in ['oracle', 'postgresql']: drop_constraint('REQUESTS_STATE_CHK', 'requests', type_='check') create_check_constraint(constraint_name='REQUESTS_STATE_CHK', table_name='requests', condition="state in ('Q', 'G', 'S', 'D', 'F', 'L', 'N', 'O', 'A', 'U')") elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 5: create_check_constraint(constraint_name='REQUESTS_STATE_CHK', table_name='requests', condition="state in ('Q', 'G', 'S', 'D', 'F', 'L', 'N', 'O', 'A', 'U')") elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 8: op.execute('ALTER TABLE ' + schema + 'requests DROP CHECK REQUESTS_STATE_CHK') # pylint: disable=no-member create_check_constraint(constraint_name='REQUESTS_STATE_CHK', table_name='requests', condition="state in ('Q', 'G', 'S', 'D', 'F', 'L', 'N', 'O', 'A', 'U')")
Example #23
Source File: 1d96f484df21_asynchronous_rules_and_rule_approval.py From rucio with Apache License 2.0 | 6 votes |
def upgrade(): ''' Upgrade the database to this revision ''' schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else '' if context.get_context().dialect.name == 'oracle': add_column('rules', sa.Column('ignore_account_limit', sa.Boolean(name='RULES_IGNORE_ACCOUNT_LIMIT_CHK'), default=False)) drop_constraint('RULES_STATE_CHK', 'rules') create_check_constraint('RULES_STATE_CHK', 'rules', "state IN ('S', 'R', 'U', 'O', 'W', 'I')") elif context.get_context().dialect.name == 'postgresql': add_column('rules', sa.Column('ignore_account_limit', sa.Boolean(name='RULES_IGNORE_ACCOUNT_LIMIT_CHK'), default=False), schema=schema[:-1]) drop_constraint('RULES_STATE_CHK', 'rules') create_check_constraint('RULES_STATE_CHK', 'rules', "state IN ('S', 'R', 'U', 'O', 'W', 'I')") elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 5: add_column('rules', sa.Column('ignore_account_limit', sa.Boolean(name='RULES_IGNORE_ACCOUNT_LIMIT_CHK'), default=False), schema=schema[:-1]) create_check_constraint('RULES_STATE_CHK', 'rules', "state IN ('S', 'R', 'U', 'O', 'W', 'I')") elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 8: add_column('rules', sa.Column('ignore_account_limit', sa.Boolean(name='RULES_IGNORE_ACCOUNT_LIMIT_CHK'), default=False), schema=schema[:-1]) op.execute('ALTER TABLE ' + schema + 'rules DROP CHECK RULES_STATE_CHK') # pylint: disable=no-member create_check_constraint('RULES_STATE_CHK', 'rules', "state IN ('S', 'R', 'U', 'O', 'W', 'I')")
Example #24
Source File: 01eaf73ab656_add_new_rule_notification_state_progress.py From rucio with Apache License 2.0 | 5 votes |
def downgrade(): ''' Downgrade the database to the previous revision ''' schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else '' if context.get_context().dialect.name == 'oracle': drop_constraint(constraint_name='RULES_NOTIFICATION_CHK', table_name='rules', type_='check') create_check_constraint(constraint_name='RULES_NOTIFICATION_CHK', table_name='rules', condition="notification in ('Y', 'N', 'C')") elif context.get_context().dialect.name == 'postgresql': # PostgreSQL does not support reducing check types, so we must work around # by changing it to the internal string type op.execute('ALTER TABLE ' + schema + 'rules DROP CONSTRAINT IF EXISTS "RULES_NOTIFICATION_CHK", ALTER COLUMN notification TYPE CHAR') # pylint: disable=no-member create_check_constraint(constraint_name='RULES_NOTIFICATION_CHK', table_name='rules', condition="notification in ('Y', 'N', 'C')") elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 5: create_check_constraint(constraint_name='RULES_NOTIFICATION_CHK', table_name='rules', condition="notification in ('Y', 'N', 'C')") elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 8: op.execute('ALTER TABLE ' + schema + 'rules DROP CHECK RULES_NOTIFICATION_CHK') # pylint: disable=no-member create_check_constraint(constraint_name='RULES_NOTIFICATION_CHK', table_name='rules', condition="notification in ('Y', 'N', 'C')")
Example #25
Source File: 0718ed97e5b3_add_tablename_to_resource_type.py From gnocchi with Apache License 2.0 | 5 votes |
def upgrade(): op.add_column("resource_type", sa.Column('tablename', sa.String(18), nullable=True)) resource_type = sa.Table( 'resource_type', sa.MetaData(), sa.Column('name', sa.String(255), nullable=False), sa.Column('tablename', sa.String(18), nullable=True) ) op.execute(resource_type.update().where( resource_type.c.name == "instance_network_interface" ).values({'tablename': op.inline_literal("'instance_net_int'")})) op.execute(resource_type.update().where( resource_type.c.name != "instance_network_interface" ).values({'tablename': resource_type.c.name})) op.alter_column("resource_type", "tablename", type_=sa.String(18), nullable=False) op.create_unique_constraint("uniq_resource_type0tablename", "resource_type", ["tablename"])
Example #26
Source File: 2e0b912062d1_drop_useless_enum.py From gnocchi with Apache License 2.0 | 5 votes |
def upgrade(): bind = op.get_bind() if bind and bind.engine.name == "postgresql": # NOTE(sileht): we use IF exists because if the database have # been created from scratch with 2.1 the enum doesn't exists op.execute("DROP TYPE IF EXISTS resource_type_enum")
Example #27
Source File: 2020-04-26_d5dba845418b_add_epoch_column_for_smarter_refetch_.py From ReadableWebProxy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def upgrade(): op.execute("SET statement_timeout TO 144000000;") # ### commands auto generated by Alembic - please adjust! ### op.add_column('raw_web_pages', sa.Column('epoch', sa.Integer(), nullable=True)) op.add_column('raw_web_pages_version', sa.Column('epoch', sa.Integer(), autoincrement=False, nullable=True)) op.add_column('web_pages', sa.Column('epoch', sa.Integer(), nullable=True)) op.add_column('web_pages_version', sa.Column('epoch', sa.Integer(), autoincrement=False, nullable=True)) # ### end Alembic commands ###
Example #28
Source File: 00041_5a974b8e4966_add_new_enum_value.py From ReadableWebProxy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def upgrade(): ### commands auto generated by Alembic - please adjust! ### op.execute("COMMIT") op.execute("ALTER TYPE dlstate_enum ADD VALUE 'specialty_blocked';") ### end Alembic commands ###
Example #29
Source File: 5c4f93e5bb4_mysql_float_to_timestamp.py From gnocchi with Apache License 2.0 | 5 votes |
def upgrade(): bind = op.get_bind() if bind and bind.engine.name == "mysql": op.execute("SET time_zone = '+00:00'") # NOTE(jd) So that crappy engine that is MySQL does not have "ALTER # TABLE … USING …". We need to copy everything and convert… for table_name, column_name in (("resource", "started_at"), ("resource", "ended_at"), ("resource", "revision_start"), ("resource_history", "started_at"), ("resource_history", "ended_at"), ("resource_history", "revision_start"), ("resource_history", "revision_end"), ("resource_type", "updated_at")): nullable = column_name == "ended_at" existing_type = sa.types.DECIMAL( precision=20, scale=6, asdecimal=True) existing_col = sa.Column( column_name, existing_type, nullable=nullable) temp_col = sa.Column( column_name + "_ts", sqlalchemy_types.TimestampUTC(), nullable=True) op.add_column(table_name, temp_col) t = sa.sql.table(table_name, existing_col, temp_col) op.execute(t.update().values( **{column_name + "_ts": func.from_unixtime(existing_col)})) op.drop_column(table_name, column_name) op.alter_column(table_name, column_name + "_ts", nullable=nullable, type_=sqlalchemy_types.TimestampUTC(), existing_nullable=nullable, existing_type=existing_type, new_column_name=column_name)
Example #30
Source File: 2020-04-27_8b536bc5d716_add_skipped_enum_value.py From ReadableWebProxy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def upgrade(): ### commands auto generated by Alembic - please adjust! ### op.execute("COMMIT") op.execute("ALTER TYPE dlstate_enum ADD VALUE 'skipped';") ### end Alembic commands ###