##// END OF EJS Templates
fixed imports on migrate, added getting current version from database
marcink -
r835:08d2dcd7 beta
parent child Browse files
Show More
@@ -0,0 +1,20 b''
1 [db_settings]
2 # Used to identify which repository this database is versioned under.
3 # You can use the name of your project.
4 repository_id=rhodecode_db_migrations
5
6 # The name of the database table used to track the schema version.
7 # This name shouldn't already be used by your project.
8 # If this is changed once a database is under version control, you'll need to
9 # change the table name in each database too.
10 version_table=db_migrate_version
11
12 # When committing a change script, Migrate will attempt to generate the
13 # sql for all supported databases; normally, if one of them fails - probably
14 # because you don't have that database installed - it is ignored and the
15 # commit continues, perhaps ending successfully.
16 # Databases in this list MUST compile successfully during a commit, or the
17 # entire commit will fail. List the databases your application will actually
18 # be using to ensure your updates to that database work properly.
19 # This must be a list; example: ['postgres','sqlite']
20 required_dbs=['sqlite']
@@ -1,8 +1,15 b''
1 #!/usr/bin/env python
1 # -*- coding: utf-8 -*-
2 # encoding: utf-8
2 """
3 # database management for RhodeCode
3 rhodecode.lib.db_manage
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
4 ~~~~~~~~~~~~~~~~~~~~~~~
5 #
5
6 Database creation, and setup module for RhodeCode
7
8 :created_on: Apr 10, 2010
9 :author: marcink
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
12 """
6 # This program is free software; you can redistribute it and/or
13 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
14 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2
15 # as published by the Free Software Foundation; version 2
@@ -18,25 +25,24 b''
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
26 # MA 02110-1301, USA.
20
27
21 """
22 Created on April 10, 2010
23 database management and creation for RhodeCode
24 @author: marcink
25 """
26
27 from os.path import dirname as dn, join as jn
28 import os
28 import os
29 import sys
29 import sys
30 import uuid
30 import uuid
31 import logging
32 from os.path import dirname as dn, join as jn
33
34 from rhodecode import __dbversion__
35 from rhodecode.model.db import
36 from rhodecode.model import meta
31
37
32 from rhodecode.lib.auth import get_crypt_password
38 from rhodecode.lib.auth import get_crypt_password
33 from rhodecode.lib.utils import ask_ok
39 from rhodecode.lib.utils import ask_ok
34 from rhodecode.model import init_model
40 from rhodecode.model import init_model
35 from rhodecode.model.db import User, Permission, RhodeCodeUi, RhodeCodeSettings, \
41 from rhodecode.model.db import User, Permission, RhodeCodeUi, RhodeCodeSettings, \
36 UserToPerm
42 UserToPerm, DbMigrateVersion
37 from rhodecode.model import meta
43
38 from sqlalchemy.engine import create_engine
44 from sqlalchemy.engine import create_engine
39 import logging
45
40
46
41 log = logging.getLogger(__name__)
47 log = logging.getLogger(__name__)
42
48
@@ -83,8 +89,6 b' class DbManage(object):'
83
89
84
90
85 def set_db_version(self):
91 def set_db_version(self):
86 from rhodecode import __dbversion__
87 from rhodecode.model.db import DbMigrateVersion
88 try:
92 try:
89 ver = DbMigrateVersion()
93 ver = DbMigrateVersion()
90 ver.version = __dbversion__
94 ver.version = __dbversion__
@@ -25,10 +25,14 b''
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 # MA 02110-1301, USA.
26 # MA 02110-1301, USA.
27
27
28 from rhodecode.lib.utils import BasePasterCommand
28 import logging
29 from sqlalchemy import engine_from_config
30
31 from rhodecode.lib.dbmigrate.migrate.exceptions import \
32 DatabaseNotControlledError
29 from rhodecode.lib.utils import BasePasterCommand, Command, add_cache
33 from rhodecode.lib.utils import BasePasterCommand, Command, add_cache
30
34
31 from sqlalchemy import engine_from_config
35 log = logging.getLogger(__name__)
32
36
33 class UpgradeDb(BasePasterCommand):
37 class UpgradeDb(BasePasterCommand):
34 """Command used for paster to upgrade our database to newer version
38 """Command used for paster to upgrade our database to newer version
@@ -46,10 +50,24 b' class UpgradeDb(BasePasterCommand):'
46 def command(self):
50 def command(self):
47 from pylons import config
51 from pylons import config
48 add_cache(config)
52 add_cache(config)
49 engine = engine_from_config(config, 'sqlalchemy.db1.')
53 #engine = engine_from_config(config, 'sqlalchemy.db1.')
50 print engine
54 #rint engine
51 raise NotImplementedError('Not implemented yet')
55
56 from rhodecode.lib.dbmigrate.migrate.versioning import api
57 path = 'rhodecode/lib/dbmigrate'
58
52
59
60 try:
61 curr_version = api.db_version(config['sqlalchemy.db1.url'], path)
62 msg = ('Found current database under version'
63 ' control with version %s' % curr_version)
64
65 except (RuntimeError, DatabaseNotControlledError), e:
66 curr_version = 0
67 msg = ('Current database is not under version control setting'
68 ' as version %s' % curr_version)
69
70 print msg
53
71
54 def update_parser(self):
72 def update_parser(self):
55 self.parser.add_option('--sql',
73 self.parser.add_option('--sql',
@@ -5,5 +5,5 b''
5 using Python.
5 using Python.
6 """
6 """
7
7
8 from migrate.versioning import *
8 from rhodecode.lib.dbmigrate.migrate.versioning import *
9 from migrate.changeset import *
9 from rhodecode.lib.dbmigrate.migrate.changeset import *
@@ -18,8 +18,8 b' SQLA_06 = _sa_version >= (0, 6)'
18 del re
18 del re
19 del _sa_version
19 del _sa_version
20
20
21 from migrate.changeset.schema import *
21 from rhodecode.lib.dbmigrate.migrate.changeset.schema import *
22 from migrate.changeset.constraint import *
22 from rhodecode.lib.dbmigrate.migrate.changeset.constraint import *
23
23
24 sqlalchemy.schema.Table.__bases__ += (ChangesetTable, )
24 sqlalchemy.schema.Table.__bases__ += (ChangesetTable, )
25 sqlalchemy.schema.Column.__bases__ += (ChangesetColumn, )
25 sqlalchemy.schema.Column.__bases__ += (ChangesetColumn, )
@@ -16,8 +16,8 b' from sqlalchemy.schema import (ForeignKe'
16 UniqueConstraint,
16 UniqueConstraint,
17 Index)
17 Index)
18
18
19 from migrate import exceptions
19 from rhodecode.lib.dbmigrate.migrate import exceptions
20 from migrate.changeset import constraint, SQLA_06
20 from rhodecode.lib.dbmigrate.migrate.changeset import constraint, SQLA_06
21
21
22 if not SQLA_06:
22 if not SQLA_06:
23 from sqlalchemy.sql.compiler import SchemaGenerator, SchemaDropper
23 from sqlalchemy.sql.compiler import SchemaGenerator, SchemaDropper
@@ -3,8 +3,8 b''
3 """
3 """
4 from sqlalchemy import schema
4 from sqlalchemy import schema
5
5
6 from migrate.exceptions import *
6 from rhodecode.lib.dbmigrate.migrate.exceptions import *
7 from migrate.changeset import SQLA_06
7 from rhodecode.lib.dbmigrate.migrate.changeset import SQLA_06
8
8
9 class ConstraintChangeset(object):
9 class ConstraintChangeset(object):
10 """Base class for Constraint classes."""
10 """Base class for Constraint classes."""
@@ -27,7 +27,7 b' class ConstraintChangeset(object):'
27
27
28 def __do_imports(self, visitor_name, *a, **kw):
28 def __do_imports(self, visitor_name, *a, **kw):
29 engine = kw.pop('engine', self.table.bind)
29 engine = kw.pop('engine', self.table.bind)
30 from migrate.changeset.databases.visitor import (get_engine_visitor,
30 from rhodecode.lib.dbmigrate.migrate.changeset.databases.visitor import (get_engine_visitor,
31 run_single_visitor)
31 run_single_visitor)
32 visitorcallable = get_engine_visitor(engine, visitor_name)
32 visitorcallable = get_engine_visitor(engine, visitor_name)
33 run_single_visitor(engine, visitorcallable, self, *a, **kw)
33 run_single_visitor(engine, visitorcallable, self, *a, **kw)
@@ -3,8 +3,8 b''
3 """
3 """
4 from sqlalchemy.databases import firebird as sa_base
4 from sqlalchemy.databases import firebird as sa_base
5
5
6 from migrate import exceptions
6 from rhodecode.lib.dbmigrate.migrate import exceptions
7 from migrate.changeset import ansisql, SQLA_06
7 from rhodecode.lib.dbmigrate.migrate.changeset import ansisql, SQLA_06
8
8
9
9
10 if SQLA_06:
10 if SQLA_06:
@@ -5,8 +5,8 b''
5 from sqlalchemy.databases import mysql as sa_base
5 from sqlalchemy.databases import mysql as sa_base
6 from sqlalchemy import types as sqltypes
6 from sqlalchemy import types as sqltypes
7
7
8 from migrate import exceptions
8 from rhodecode.lib.dbmigrate.migrate import exceptions
9 from migrate.changeset import ansisql, SQLA_06
9 from rhodecode.lib.dbmigrate.migrate.changeset import ansisql, SQLA_06
10
10
11
11
12 if not SQLA_06:
12 if not SQLA_06:
@@ -4,8 +4,8 b''
4 import sqlalchemy as sa
4 import sqlalchemy as sa
5 from sqlalchemy.databases import oracle as sa_base
5 from sqlalchemy.databases import oracle as sa_base
6
6
7 from migrate import exceptions
7 from rhodecode.lib.dbmigrate.migrate import exceptions
8 from migrate.changeset import ansisql, SQLA_06
8 from rhodecode.lib.dbmigrate.migrate.changeset import ansisql, SQLA_06
9
9
10
10
11 if not SQLA_06:
11 if not SQLA_06:
@@ -3,7 +3,7 b''
3
3
4 .. _`PostgreSQL`: http://www.postgresql.org/
4 .. _`PostgreSQL`: http://www.postgresql.org/
5 """
5 """
6 from migrate.changeset import ansisql, SQLA_06
6 from rhodecode.lib.dbmigrate.migrate.changeset import ansisql, SQLA_06
7
7
8 if not SQLA_06:
8 if not SQLA_06:
9 from sqlalchemy.databases import postgres as sa_base
9 from sqlalchemy.databases import postgres as sa_base
@@ -8,8 +8,8 b' from copy import copy'
8
8
9 from sqlalchemy.databases import sqlite as sa_base
9 from sqlalchemy.databases import sqlite as sa_base
10
10
11 from migrate import exceptions
11 from rhodecode.lib.dbmigrate.migrate import exceptions
12 from migrate.changeset import ansisql, SQLA_06
12 from rhodecode.lib.dbmigrate.migrate.changeset import ansisql, SQLA_06
13
13
14
14
15 if not SQLA_06:
15 if not SQLA_06:
@@ -3,8 +3,8 b''
3 """
3 """
4 import sqlalchemy as sa
4 import sqlalchemy as sa
5
5
6 from migrate.changeset import ansisql
6 from rhodecode.lib.dbmigrate.migrate.changeset import ansisql
7 from migrate.changeset.databases import (sqlite,
7 from rhodecode.lib.dbmigrate.migrate.changeset.databases import (sqlite,
8 postgres,
8 postgres,
9 mysql,
9 mysql,
10 oracle,
10 oracle,
@@ -10,9 +10,9 b' import sqlalchemy'
10 from sqlalchemy.schema import ForeignKeyConstraint
10 from sqlalchemy.schema import ForeignKeyConstraint
11 from sqlalchemy.schema import UniqueConstraint
11 from sqlalchemy.schema import UniqueConstraint
12
12
13 from migrate.exceptions import *
13 from rhodecode.lib.dbmigrate.migrate.exceptions import *
14 from migrate.changeset import SQLA_06
14 from rhodecode.lib.dbmigrate.migrate.changeset import SQLA_06
15 from migrate.changeset.databases.visitor import (get_engine_visitor,
15 from rhodecode.lib.dbmigrate.migrate.changeset.databases.visitor import (get_engine_visitor,
16 run_single_visitor)
16 run_single_visitor)
17
17
18
18
@@ -29,10 +29,10 b' import sys'
29 import inspect
29 import inspect
30 import logging
30 import logging
31
31
32 from migrate import exceptions
32 from rhodecode.lib.dbmigrate.migrate import exceptions
33 from migrate.versioning import (repository, schema, version,
33 from rhodecode.lib.dbmigrate.migrate.versioning import (repository, schema, version,
34 script as script_) # command name conflict
34 script as script_) # command name conflict
35 from migrate.versioning.util import catch_known_errors, with_engine
35 from rhodecode.lib.dbmigrate.migrate.versioning.util import catch_known_errors, with_engine
36
36
37
37
38 log = logging.getLogger(__name__)
38 log = logging.getLogger(__name__)
@@ -4,8 +4,8 b''
4
4
5 from ConfigParser import ConfigParser
5 from ConfigParser import ConfigParser
6
6
7 from migrate.versioning.config import *
7 from rhodecode.lib.dbmigrate.migrate.versioning.config import *
8 from migrate.versioning import pathed
8 from rhodecode.lib.dbmigrate.migrate.versioning import pathed
9
9
10
10
11 class Parser(ConfigParser):
11 class Parser(ConfigParser):
@@ -11,9 +11,8 b' import logging'
11
11
12 import sqlalchemy
12 import sqlalchemy
13
13
14 import migrate
14 from rhodecode.lib.dbmigrate import migrate
15 import migrate.changeset
15 from rhodecode.lib.dbmigrate.migrate import changeset
16
17
16
18 log = logging.getLogger(__name__)
17 log = logging.getLogger(__name__)
19 HEADER = """
18 HEADER = """
@@ -138,7 +137,7 b' class ModelGenerator(object):'
138
137
139 def toUpgradeDowngradePython(self, indent=' '):
138 def toUpgradeDowngradePython(self, indent=' '):
140 ''' Assume model is most current and database is out-of-date. '''
139 ''' Assume model is most current and database is out-of-date. '''
141 decls = ['from migrate.changeset import schema',
140 decls = ['from rhodecode.lib.dbmigrate.migrate.changeset import schema',
142 'meta = MetaData()']
141 'meta = MetaData()']
143 for table in self._get_tables(
142 for table in self._get_tables(
144 missingA=True,missingB=True,modified=True
143 missingA=True, missingB=True, modified=True
@@ -6,9 +6,9 b' import os'
6 import shutil
6 import shutil
7 import logging
7 import logging
8
8
9 from migrate import exceptions
9 from rhodecode.lib.dbmigrate.migrate import exceptions
10 from migrate.versioning.config import *
10 from rhodecode.lib.dbmigrate.migrate.versioning.config import *
11 from migrate.versioning.util import KeyedInstance
11 from rhodecode.lib.dbmigrate.migrate.versioning.util import KeyedInstance
12
12
13
13
14 log = logging.getLogger(__name__)
14 log = logging.getLogger(__name__)
@@ -9,10 +9,10 b' import logging'
9 from pkg_resources import resource_filename
9 from pkg_resources import resource_filename
10 from tempita import Template as TempitaTemplate
10 from tempita import Template as TempitaTemplate
11
11
12 from migrate import exceptions
12 from rhodecode.lib.dbmigrate.migrate import exceptions
13 from migrate.versioning import version, pathed, cfgparse
13 from rhodecode.lib.dbmigrate.migrate.versioning import version, pathed, cfgparse
14 from migrate.versioning.template import Template
14 from rhodecode.lib.dbmigrate.migrate.versioning.template import Template
15 from migrate.versioning.config import *
15 from rhodecode.lib.dbmigrate.migrate.versioning.config import *
16
16
17
17
18 log = logging.getLogger(__name__)
18 log = logging.getLogger(__name__)
@@ -10,11 +10,11 b' from sqlalchemy.sql import and_'
10 from sqlalchemy import exceptions as sa_exceptions
10 from sqlalchemy import exceptions as sa_exceptions
11 from sqlalchemy.sql import bindparam
11 from sqlalchemy.sql import bindparam
12
12
13 from migrate import exceptions
13 from rhodecode.lib.dbmigrate.migrate import exceptions
14 from migrate.versioning import genmodel, schemadiff
14 from rhodecode.lib.dbmigrate.migrate.versioning import genmodel, schemadiff
15 from migrate.versioning.repository import Repository
15 from rhodecode.lib.dbmigrate.migrate.versioning.repository import Repository
16 from migrate.versioning.util import load_model
16 from rhodecode.lib.dbmigrate.migrate.versioning.util import load_model
17 from migrate.versioning.version import VerNum
17 from rhodecode.lib.dbmigrate.migrate.versioning.version import VerNum
18
18
19
19
20 log = logging.getLogger(__name__)
20 log = logging.getLogger(__name__)
@@ -5,7 +5,7 b''
5 import logging
5 import logging
6 import sqlalchemy
6 import sqlalchemy
7
7
8 from migrate.changeset import SQLA_06
8 from rhodecode.lib.dbmigrate.migrate.changeset import SQLA_06
9 from sqlalchemy.types import Float
9 from sqlalchemy.types import Float
10
10
11 log = logging.getLogger(__name__)
11 log = logging.getLogger(__name__)
@@ -1,6 +1,6 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
2 # -*- coding: utf-8 -*-
3
3
4 from migrate.versioning.script.base import BaseScript
4 from rhodecode.lib.dbmigrate.migrate.versioning.script.base import BaseScript
5 from migrate.versioning.script.py import PythonScript
5 from rhodecode.lib.dbmigrate.migrate.versioning.script.py import PythonScript
6 from migrate.versioning.script.sql import SqlScript
6 from rhodecode.lib.dbmigrate.migrate.versioning.script.sql import SqlScript
@@ -2,9 +2,9 b''
2 # -*- coding: utf-8 -*-
2 # -*- coding: utf-8 -*-
3 import logging
3 import logging
4
4
5 from migrate import exceptions
5 from rhodecode.lib.dbmigrate.migrate import exceptions
6 from migrate.versioning.config import operations
6 from rhodecode.lib.dbmigrate.migrate.versioning.config import operations
7 from migrate.versioning import pathed
7 from rhodecode.lib.dbmigrate.migrate.versioning import pathed
8
8
9
9
10 log = logging.getLogger(__name__)
10 log = logging.getLogger(__name__)
@@ -6,13 +6,13 b' import warnings'
6 import logging
6 import logging
7 from StringIO import StringIO
7 from StringIO import StringIO
8
8
9 import migrate
9 from rhodecode.lib.dbmigrate import migrate
10 from migrate.versioning import genmodel, schemadiff
10 from rhodecode.lib.dbmigrate.migrate.versioning import genmodel, schemadiff
11 from migrate.versioning.config import operations
11 from rhodecode.lib.dbmigrate.migrate.versioning.config import operations
12 from migrate.versioning.template import Template
12 from rhodecode.lib.dbmigrate.migrate.versioning.template import Template
13 from migrate.versioning.script import base
13 from rhodecode.lib.dbmigrate.migrate.versioning.script import base
14 from migrate.versioning.util import import_path, load_model, with_engine
14 from rhodecode.lib.dbmigrate.migrate.versioning.util import import_path, load_model, with_engine
15 from migrate.exceptions import MigrateDeprecationWarning, InvalidScriptError, ScriptError
15 from rhodecode.lib.dbmigrate.migrate.exceptions import MigrateDeprecationWarning, InvalidScriptError, ScriptError
16
16
17 log = logging.getLogger(__name__)
17 log = logging.getLogger(__name__)
18 __all__ = ['PythonScript']
18 __all__ = ['PythonScript']
@@ -52,7 +52,7 b' class PythonScript(base.BaseScript):'
52
52
53 if isinstance(repository, basestring):
53 if isinstance(repository, basestring):
54 # oh dear, an import cycle!
54 # oh dear, an import cycle!
55 from migrate.versioning.repository import Repository
55 from rhodecode.lib.dbmigrate.migrate.versioning.repository import Repository
56 repository = Repository(repository)
56 repository = Repository(repository)
57
57
58 oldmodel = load_model(oldmodel)
58 oldmodel = load_model(oldmodel)
@@ -3,8 +3,8 b''
3 import logging
3 import logging
4 import shutil
4 import shutil
5
5
6 from migrate.versioning.script import base
6 from rhodecode.lib.dbmigrate.migrate.versioning.script import base
7 from migrate.versioning.template import Template
7 from rhodecode.lib.dbmigrate.migrate.versioning.template import Template
8
8
9
9
10 log = logging.getLogger(__name__)
10 log = logging.getLogger(__name__)
@@ -8,10 +8,10 b' import inspect'
8 import logging
8 import logging
9 from optparse import OptionParser, BadOptionError
9 from optparse import OptionParser, BadOptionError
10
10
11 from migrate import exceptions
11 from rhodecode.lib.dbmigrate.migrate import exceptions
12 from migrate.versioning import api
12 from rhodecode.lib.dbmigrate.migrate.versioning import api
13 from migrate.versioning.config import *
13 from rhodecode.lib.dbmigrate.migrate.versioning.config import *
14 from migrate.versioning.util import asbool
14 from rhodecode.lib.dbmigrate.migrate.versioning.util import asbool
15
15
16
16
17 alias = dict(
17 alias = dict(
@@ -7,8 +7,8 b' import sys'
7
7
8 from pkg_resources import resource_filename
8 from pkg_resources import resource_filename
9
9
10 from migrate.versioning.config import *
10 from rhodecode.lib.dbmigrate.migrate.versioning.config import *
11 from migrate.versioning import pathed
11 from rhodecode.lib.dbmigrate.migrate.versioning import pathed
12
12
13
13
14 class Collection(pathed.Pathed):
14 class Collection(pathed.Pathed):
@@ -34,7 +34,7 b' class SQLScriptCollection(Collection):'
34 class Template(pathed.Pathed):
34 class Template(pathed.Pathed):
35 """Finds the paths/packages of various Migrate templates.
35 """Finds the paths/packages of various Migrate templates.
36
36
37 :param path: Templates are loaded from migrate package
37 :param path: Templates are loaded from rhodecode.lib.dbmigrate.migrate package
38 if `path` is not provided.
38 if `path` is not provided.
39 """
39 """
40 pkg = 'migrate.versioning.templates'
40 pkg = 'migrate.versioning.templates'
@@ -11,9 +11,9 b' from sqlalchemy import create_engine'
11 from sqlalchemy.engine import Engine
11 from sqlalchemy.engine import Engine
12 from sqlalchemy.pool import StaticPool
12 from sqlalchemy.pool import StaticPool
13
13
14 from migrate import exceptions
14 from rhodecode.lib.dbmigrate.migrate import exceptions
15 from migrate.versioning.util.keyedinstance import KeyedInstance
15 from rhodecode.lib.dbmigrate.migrate.versioning.util.keyedinstance import KeyedInstance
16 from migrate.versioning.util.importpath import import_path
16 from rhodecode.lib.dbmigrate.migrate.versioning.util.importpath import import_path
17
17
18
18
19 log = logging.getLogger(__name__)
19 log = logging.getLogger(__name__)
@@ -6,8 +6,8 b' import re'
6 import shutil
6 import shutil
7 import logging
7 import logging
8
8
9 from migrate import exceptions
9 from rhodecode.lib.dbmigrate.migrate import exceptions
10 from migrate.versioning import pathed, script
10 from rhodecode.lib.dbmigrate.migrate.versioning import pathed, script
11
11
12
12
13 log = logging.getLogger(__name__)
13 log = logging.getLogger(__name__)
General Comments 0
You need to be logged in to leave comments. Login now