From d2a5adc027f81407612451c2eb1394181870dd2f Mon Sep 17 00:00:00 2001 From: Khanh Ngo Date: Fri, 22 Jun 2018 18:02:01 +0700 Subject: [PATCH] Create DB default values during the first migration --- migrations/versions/787bdba9e147_init_db.py | 50 +++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/migrations/versions/787bdba9e147_init_db.py b/migrations/versions/787bdba9e147_init_db.py index 2c66e83..aa781de 100644 --- a/migrations/versions/787bdba9e147_init_db.py +++ b/migrations/versions/787bdba9e147_init_db.py @@ -16,6 +16,53 @@ branch_labels = None depends_on = None +def seed_data(): + role_table = sa.sql.table('role', + sa.sql.column('id', sa.Integer), + sa.sql.column('name', sa.String), + sa.sql.column('description', sa.String) + ) + + setting_table = sa.sql.table('setting', + sa.sql.column('id', sa.Integer), + sa.sql.column('name', sa.String), + sa.sql.column('value', sa.String) + ) + + template_table = sa.sql.table('domain_template', + sa.sql.column('id', sa.Integer), + sa.sql.column('name', sa.String), + sa.sql.column('description', sa.String) + ) + + op.bulk_insert(role_table, + [ + {'id': 1, 'name': 'Administrator', 'description': 'Administrator'}, + {'id': 2, 'name': 'User', 'description': 'User'} + ] + ) + + op.bulk_insert(setting_table, + [ + {'id': 1, 'name': 'maintenance', 'value': 'False'}, + {'id': 2, 'name': 'fullscreen_layout', 'value': 'True'}, + {'id': 3, 'name': 'record_helper', 'value': 'True'}, + {'id': 4, 'name': 'login_ldap_first', 'value': 'True'}, + {'id': 5, 'name': 'default_record_table_size', 'value': '15'}, + {'id': 6, 'name': 'default_domain_table_size', 'value': '10'}, + {'id': 7, 'name': 'auto_ptr', 'value': 'False'} + ] + ) + + op.bulk_insert(template_table, + [ + {id: 1, 'name': 'basic_template_1', 'description': 'Basic Template #1'}, + {id: 2, 'name': 'basic_template_2', 'description': 'Basic Template #2'}, + {id: 3, 'name': 'basic_template_3', 'description': 'Basic Template #3'} + ] + ) + + def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('account', @@ -120,6 +167,9 @@ def upgrade(): ) # ### end Alembic commands ### + # Insert default values to the database + seed_data() + def downgrade(): # ### commands auto generated by Alembic - please adjust! ###