11 def feed_initial_data(conn
):
12 conn
.execute(aurweb
.schema
.AccountTypes
.insert(), [
13 {'ID': 1, 'AccountType': 'User'},
14 {'ID': 2, 'AccountType': 'Trusted User'},
15 {'ID': 3, 'AccountType': 'Developer'},
16 {'ID': 4, 'AccountType': 'Trusted User & Developer'},
18 conn
.execute(aurweb
.schema
.DependencyTypes
.insert(), [
19 {'ID': 1, 'Name': 'depends'},
20 {'ID': 2, 'Name': 'makedepends'},
21 {'ID': 3, 'Name': 'checkdepends'},
22 {'ID': 4, 'Name': 'optdepends'},
24 conn
.execute(aurweb
.schema
.RelationTypes
.insert(), [
25 {'ID': 1, 'Name': 'conflicts'},
26 {'ID': 2, 'Name': 'provides'},
27 {'ID': 3, 'Name': 'replaces'},
29 conn
.execute(aurweb
.schema
.RequestTypes
.insert(), [
30 {'ID': 1, 'Name': 'deletion'},
31 {'ID': 2, 'Name': 'orphan'},
32 {'ID': 3, 'Name': 'merge'},
37 # Ensure Alembic is fine before we do the real work, in order not to fail at
38 # the last step and leave the database in an inconsistent state. The
39 # configuration is loaded lazily, so we query it to force its loading.
41 alembic_config
= alembic
.config
.Config('alembic.ini')
42 alembic_config
.get_main_option('script_location')
44 engine
= sqlalchemy
.create_engine(aurweb
.db
.get_sqlalchemy_url(),
45 echo
=(args
.verbose
>= 1))
46 aurweb
.schema
.metadata
.create_all(engine
)
47 feed_initial_data(engine
.connect())
50 alembic
.command
.stamp(alembic_config
, 'head')
53 if __name__
== '__main__':
54 parser
= argparse
.ArgumentParser(
55 prog
='python -m aurweb.initdb',
56 description
='Initialize the aurweb database.')
57 parser
.add_argument('-v', '--verbose', action
='count', default
=0,
58 help='increase verbosity')
59 parser
.add_argument('--no-alembic',
60 help='disable Alembic migrations support',
61 dest
='use_alembic', action
='store_false')
62 args
= parser
.parse_args()