Passed
Push — dev ( 836244...247d11 )
by Stephan
01:23 queued 11s
created

data.datasets.database.setup()   A

Complexity

Conditions 3

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
import functools
2
3
from egon.data import db
4
from egon.data.datasets import Dataset
5
6
7
def setup():
8
    """ Initialize the local database used for data processing. """
9
    engine = db.engine()
10
    with engine.connect().execution_options(autocommit=True) as connection:
11
        for extension in ["hstore", "postgis", "postgis_raster", "pgrouting"]:
12
            connection.execute(f"CREATE EXTENSION IF NOT EXISTS {extension}")
13
14
15
Setup = functools.partial(
16
    Dataset,
17
    name="Database Setup",
18
    version="0.0.0",
19
    dependencies=[],
20
    tasks=setup,
21
)
22