root / snf-pithos-backend / pithos / backends / lib / sqlalchemy / alembic / versions / 4451e165da19_set_container_quota_.py @ 78e1f8da
History | View | Annotate | Download (1.2 kB)
1 |
"""Set container quota source
|
---|---|
2 |
|
3 |
Revision ID: 4451e165da19
|
4 |
Revises: 3b62b3f1bf6c
|
5 |
Create Date: 2013-09-27 13:36:27.477141
|
6 |
|
7 |
"""
|
8 |
|
9 |
# revision identifiers, used by Alembic.
|
10 |
revision = '4451e165da19'
|
11 |
down_revision = '54dbdde2d187'
|
12 |
|
13 |
from alembic import op |
14 |
import sqlalchemy as sa |
15 |
from sqlalchemy.sql import table, column, select |
16 |
|
17 |
ROOTNODE = 0
|
18 |
|
19 |
|
20 |
def upgrade(): |
21 |
connection = op.get_bind() |
22 |
|
23 |
nodes = table('nodes',
|
24 |
column('path', sa.String(2048)), |
25 |
column('node', sa.Integer),
|
26 |
column('parent', sa.Integer))
|
27 |
n1 = nodes.alias('n1')
|
28 |
n2 = nodes.alias('n2')
|
29 |
policy = table('policy',
|
30 |
column('node', sa.Integer),
|
31 |
column('key', sa.String(128)), |
32 |
column('value', sa.String(256))) |
33 |
|
34 |
s = select([n2.c.node, n1.c.path]) |
35 |
s = s.where(n2.c.parent == n1.c.node) |
36 |
s = s.where(n1.c.parent == ROOTNODE) |
37 |
s = s.where(n1.c.node != ROOTNODE) |
38 |
r = connection.execute(s) |
39 |
rows = r.fetchall() |
40 |
op.bulk_insert(policy, [{'node': node,
|
41 |
'key': 'project', |
42 |
'value': path} for node, path in rows]) |
43 |
|
44 |
|
45 |
def downgrade(): |
46 |
pass
|