Revision 5f8bbf54

b/snf-pithos-backend/pithos/backends/lib/sqlalchemy/alembic.ini
1
# A generic, single database configuration.
2

  
3
[alembic]
4
# path to migration scripts
5
script_location = alembic
6

  
7
# template used to generate migration files
8
# file_template = %%(rev)s_%%(slug)s
9

  
10
# set to 'true' to run the environment during
11
# the 'revision' command, regardless of autogenerate
12
# revision_environment = false
13

  
14
#sqlalchemy.url = driver://user:pass@localhost/dbname
15
sqlalchemy.url = postgresql://pithos@:5432/pithos_prod
16

  
17
# Logging configuration
18
[loggers]
19
keys = root,sqlalchemy,alembic
20

  
21
[handlers]
22
keys = console
23

  
24
[formatters]
25
keys = generic
26

  
27
[logger_root]
28
level = WARN
29
handlers = console
30
qualname =
31

  
32
[logger_sqlalchemy]
33
level = WARN
34
handlers =
35
qualname = sqlalchemy.engine
36

  
37
[logger_alembic]
38
level = INFO
39
handlers =
40
qualname = alembic
41

  
42
[handler_console]
43
class = StreamHandler
44
args = (sys.stderr,)
45
level = NOTSET
46
formatter = generic
47

  
48
[formatter_generic]
49
format = %(levelname)-5.5s [%(name)s] %(message)s
50
datefmt = %H:%M:%S
b/snf-pithos-backend/pithos/backends/lib/sqlalchemy/alembic/README
1
Generic single-database configuration.
b/snf-pithos-backend/pithos/backends/lib/sqlalchemy/alembic/env.py
1
from __future__ import with_statement
2
from alembic import context
3
from sqlalchemy import engine_from_config, pool
4
from logging.config import fileConfig
5

  
6
# this is the Alembic Config object, which provides
7
# access to the values within the .ini file in use.
8
config = context.config
9

  
10
# Interpret the config file for Python logging. 
11
# This line sets up loggers basically.
12
fileConfig(config.config_file_name)
13

  
14
# add your model's MetaData object here
15
# for 'autogenerate' support
16
# from myapp import mymodel
17
# target_metadata = mymodel.Base.metadata
18
target_metadata = None
19

  
20
# other values from the config, defined by the needs of env.py,
21
# can be acquired:
22
# my_important_option = config.get_main_option("my_important_option")
23
# ... etc.
24

  
25
def run_migrations_offline():
26
    """Run migrations in 'offline' mode.
27

  
28
    This configures the context with just a URL
29
    and not an Engine, though an Engine is acceptable
30
    here as well.  By skipping the Engine creation
31
    we don't even need a DBAPI to be available.
32
    
33
    Calls to context.execute() here emit the given string to the
34
    script output.
35
    
36
    """
37
    url = config.get_main_option("sqlalchemy.url")
38
    context.configure(url=url)
39

  
40
    with context.begin_transaction():
41
        context.run_migrations()
42

  
43
def run_migrations_online():
44
    """Run migrations in 'online' mode.
45

  
46
    In this scenario we need to create an Engine
47
    and associate a connection with the context.
48
    
49
    """
50
    engine = engine_from_config(
51
                config.get_section(config.config_ini_section), 
52
                prefix='sqlalchemy.', 
53
                poolclass=pool.NullPool)
54

  
55
    connection = engine.connect()
56
    context.configure(
57
                connection=connection, 
58
                target_metadata=target_metadata
59
                )
60

  
61
    try:
62
        with context.begin_transaction():
63
            context.run_migrations()
64
    finally:
65
        connection.close()
66

  
67
if context.is_offline_mode():
68
    run_migrations_offline()
69
else:
70
    run_migrations_online()
71

  
b/snf-pithos-backend/pithos/backends/lib/sqlalchemy/alembic/script.py.mako
1
"""${message}
2

  
3
Revision ID: ${up_revision}
4
Revises: ${down_revision}
5
Create Date: ${create_date}
6

  
7
"""
8

  
9
# revision identifiers, used by Alembic.
10
revision = ${repr(up_revision)}
11
down_revision = ${repr(down_revision)}
12

  
13
from alembic import op
14
import sqlalchemy as sa
15
${imports if imports else ""}
16

  
17
def upgrade():
18
    ${upgrades if upgrades else "pass"}
19

  
20

  
21
def downgrade():
22
    ${downgrades if downgrades else "pass"}
b/snf-pithos-backend/pithos/backends/lib/sqlalchemy/alembic/versions/230f8ce9c90f_alter_nodes_add_colu.py
1
"""alter nodes add column latest version
2

  
3
Revision ID: 230f8ce9c90f
4
Revises: 8320b1c62d9
5
Create Date: 2012-07-17 20:32:54.466145
6

  
7
"""
8

  
9
# revision identifiers, used by Alembic.
10
revision = '230f8ce9c90f'
11
down_revision = '8320b1c62d9'
12

  
13
from alembic import op, context
14
from sqlalchemy.sql import table, column
15
from alembic import op
16

  
17
import sqlalchemy as sa
18

  
19
def upgrade():
20
    op.add_column('nodes', sa.Column('latest_version', sa.INTEGER))
21
    
22
    n = table('nodes', 
23
        column('node', sa.Integer),
24
        column('latest_version', sa.Integer)
25
    )
26
    v = table('versions', 
27
        column('node', sa.Integer),
28
        column('mtime', sa.Integer),
29
        column('serial', sa.Integer),
30
    )
31
    
32
    s = sa.select([v.c.serial]).where(n.c.node == v.c.node).order_by(v.c.mtime).limit(1)
33
    op.execute(
34
        n.update().\
35
            values({'latest_version':s})
36
            )
37

  
38
def downgrade():
39
    op.drop_column('nodes', 'latest_version')
b/snf-pithos-backend/pithos/backends/lib/sqlalchemy/alembic/versions/8320b1c62d9_create_index_nodes_p.py
1
"""create index nodes.parent
2

  
3
Revision ID: 8320b1c62d9
4
Revises: None
5
Create Date: 2012-07-17 20:31:18.790919
6

  
7
"""
8

  
9
# revision identifiers, used by Alembic.
10
revision = '8320b1c62d9'
11
down_revision = None
12

  
13
from alembic import op
14
import sqlalchemy as sa
15

  
16
def upgrade():
17
    op.create_index('idx_nodes_parent', 'nodes', ['parent'])
18

  
19
def downgrade():
20
    op.drop_index('idx_nodes_parent', tablename='nodes')

Also available in: Unified diff