initdb.py 1.48 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import aurweb.db
import aurweb.schema

import argparse
import sqlalchemy


def feed_initial_data(conn):
    conn.execute(aurweb.schema.AccountTypes.insert(), [
        {'ID': 1, 'AccountType': 'User'},
        {'ID': 2, 'AccountType': 'Trusted User'},
        {'ID': 3, 'AccountType': 'Developer'},
        {'ID': 4, 'AccountType': 'Trusted User & Developer'},
    ])
    conn.execute(aurweb.schema.DependencyTypes.insert(), [
        {'ID': 1, 'Name': 'depends'},
        {'ID': 2, 'Name': 'makedepends'},
        {'ID': 3, 'Name': 'checkdepends'},
        {'ID': 4, 'Name': 'optdepends'},
    ])
    conn.execute(aurweb.schema.RelationTypes.insert(), [
        {'ID': 1, 'Name': 'conflicts'},
        {'ID': 2, 'Name': 'provides'},
        {'ID': 3, 'Name': 'replaces'},
    ])
    conn.execute(aurweb.schema.RequestTypes.insert(), [
        {'ID': 1, 'Name': 'deletion'},
        {'ID': 2, 'Name': 'orphan'},
        {'ID': 3, 'Name': 'merge'},
    ])


def run(args):
    engine = sqlalchemy.create_engine(aurweb.db.get_sqlalchemy_url(),
                                      echo=(args.verbose >= 1))
    aurweb.schema.metadata.create_all(engine)
    feed_initial_data(engine.connect())


if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        prog='python -m aurweb.initdb',
        description='Initialize the aurweb database.')
    parser.add_argument('-v', '--verbose', action='count', default=0,
                        help='increase verbosity')
    args = parser.parse_args()
    run(args)