Show More
@@ -0,0 +1,24 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
2 | """ | |
|
3 | rhodecode.model.db | |
|
4 | ~~~~~~~~~~~~~~~~~~ | |
|
5 | ||
|
6 | Database Models for RhodeCode | |
|
7 | ||
|
8 | :created_on: Apr 08, 2010 | |
|
9 | :author: marcink | |
|
10 | :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com> | |
|
11 | :license: GPLv3, see COPYING for more details. | |
|
12 | """ | |
|
13 | # This program is free software: you can redistribute it and/or modify | |
|
14 | # it under the terms of the GNU General Public License as published by | |
|
15 | # the Free Software Foundation, either version 3 of the License, or | |
|
16 | # (at your option) any later version. | |
|
17 | # | |
|
18 | # This program is distributed in the hope that it will be useful, | |
|
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
21 | # GNU General Public License for more details. | |
|
22 | # | |
|
23 | # You should have received a copy of the GNU General Public License | |
|
24 | # along with this program. If not, see <http://www.gnu.org/licenses/>. No newline at end of file |
@@ -0,0 +1,28 b'' | |||
|
1 | import logging | |
|
2 | import datetime | |
|
3 | ||
|
4 | from sqlalchemy import * | |
|
5 | from sqlalchemy.exc import DatabaseError | |
|
6 | from sqlalchemy.orm import relation, backref, class_mapper | |
|
7 | from sqlalchemy.orm.session import Session | |
|
8 | ||
|
9 | from rhodecode.lib.dbmigrate.migrate import * | |
|
10 | from rhodecode.lib.dbmigrate.migrate.changeset import * | |
|
11 | ||
|
12 | from rhodecode.model.meta import Base | |
|
13 | ||
|
14 | log = logging.getLogger(__name__) | |
|
15 | ||
|
16 | def upgrade(migrate_engine): | |
|
17 | """ Upgrade operations go here. | |
|
18 | Don't create your own engine; bind migrate_engine to your metadata | |
|
19 | """ | |
|
20 | ||
|
21 | ||
|
22 | ||
|
23 | return | |
|
24 | ||
|
25 | ||
|
26 | def downgrade(migrate_engine): | |
|
27 | meta = MetaData() | |
|
28 | meta.bind = migrate_engine |
@@ -8,4 +8,4 b'' | |||
|
8 | 8 | from rhodecode.lib.dbmigrate.migrate.versioning import * |
|
9 | 9 | from rhodecode.lib.dbmigrate.migrate.changeset import * |
|
10 | 10 | |
|
11 |
__version__ = '0.7. |
|
|
11 | __version__ = '0.7.3.dev' No newline at end of file |
@@ -39,7 +39,7 b' class SQLiteHelper(SQLiteCommon):' | |||
|
39 | 39 | |
|
40 | 40 | insertion_string = self._modify_table(table, column, delta) |
|
41 | 41 | |
|
42 | table.create() | |
|
42 | table.create(bind=self.connection) | |
|
43 | 43 | self.append(insertion_string % {'table_name': table_name}) |
|
44 | 44 | self.execute() |
|
45 | 45 | self.append('DROP TABLE migration_tmp') |
@@ -83,6 +83,5 b' class NotSupportedError(Error):' | |||
|
83 | 83 | class InvalidConstraintError(Error): |
|
84 | 84 | """Invalid constraint error""" |
|
85 | 85 | |
|
86 | ||
|
87 | 86 | class MigrateDeprecationWarning(DeprecationWarning): |
|
88 | 87 | """Warning for deprecated features in Migrate""" |
@@ -119,7 +119,7 b' def script_sql(database, description, re' | |||
|
119 | 119 | |
|
120 | 120 | For instance, manage.py script_sql postgresql description creates: |
|
121 | 121 | repository/versions/001_description_postgresql_upgrade.sql and |
|
122 |
repository/versions/001_description_postgresql_ |
|
|
122 | repository/versions/001_description_postgresql_downgrade.sql | |
|
123 | 123 | """ |
|
124 | 124 | repo = Repository(repository) |
|
125 | 125 | repo.create_script_sql(database, description, **opts) |
@@ -212,14 +212,15 b' def test(url, repository, **opts):' | |||
|
212 | 212 | """ |
|
213 | 213 | engine = opts.pop('engine') |
|
214 | 214 | repos = Repository(repository) |
|
215 | script = repos.version(None).script() | |
|
216 | 215 | |
|
217 | 216 | # Upgrade |
|
218 | 217 | log.info("Upgrading...") |
|
218 | script = repos.version(None).script(engine.name, 'upgrade') | |
|
219 | 219 | script.run(engine, 1) |
|
220 | 220 | log.info("done") |
|
221 | 221 | |
|
222 | 222 | log.info("Downgrading...") |
|
223 | script = repos.version(None).script(engine.name, 'downgrade') | |
|
223 | 224 | script.run(engine, -1) |
|
224 | 225 | log.info("done") |
|
225 | 226 | log.info("Success") |
@@ -115,7 +115,7 b' class Repository(pathed.Pathed):' | |||
|
115 | 115 | options.setdefault('version_table', 'migrate_version') |
|
116 | 116 | options.setdefault('repository_id', name) |
|
117 | 117 | options.setdefault('required_dbs', []) |
|
118 |
options.setdefault('use_timestamp_numbering', |
|
|
118 | options.setdefault('use_timestamp_numbering', False) | |
|
119 | 119 | |
|
120 | 120 | tmpl = open(os.path.join(tmpl_dir, cls._config)).read() |
|
121 | 121 | ret = TempitaTemplate(tmpl).substitute(options) |
@@ -180,9 +180,9 b' class Repository(pathed.Pathed):' | |||
|
180 | 180 | @property |
|
181 | 181 | def use_timestamp_numbering(self): |
|
182 | 182 | """Returns use_timestamp_numbering specified in config""" |
|
183 |
|
|
|
184 | ||
|
185 |
return |
|
|
183 | if self.config.has_option('db_settings', 'use_timestamp_numbering'): | |
|
184 | return self.config.getboolean('db_settings', 'use_timestamp_numbering') | |
|
185 | return False | |
|
186 | 186 | |
|
187 | 187 | def version(self, *p, **k): |
|
188 | 188 | """API to :attr:`migrate.versioning.version.Collection.version`""" |
@@ -17,8 +17,16 b' def getDiffOfModelAgainstDatabase(metada' | |||
|
17 | 17 | :return: object which will evaluate to :keyword:`True` if there \ |
|
18 | 18 | are differences else :keyword:`False`. |
|
19 | 19 | """ |
|
20 | return SchemaDiff(metadata, | |
|
21 | sqlalchemy.MetaData(engine, reflect=True), | |
|
20 | db_metadata = sqlalchemy.MetaData(engine, reflect=True) | |
|
21 | ||
|
22 | # sqlite will include a dynamically generated 'sqlite_sequence' table if | |
|
23 | # there are autoincrement sequences in the database; this should not be | |
|
24 | # compared. | |
|
25 | if engine.dialect.name == 'sqlite': | |
|
26 | if 'sqlite_sequence' in db_metadata.tables: | |
|
27 | db_metadata.remove(db_metadata.tables['sqlite_sequence']) | |
|
28 | ||
|
29 | return SchemaDiff(metadata, db_metadata, | |
|
22 | 30 | labelA='model', |
|
23 | 31 | labelB='database', |
|
24 | 32 | excludeTables=excludeTables) |
@@ -7,4 +7,6 b" del _vars['__template_name__']" | |||
|
7 | 7 | _vars.pop('repository_name', None) |
|
8 | 8 | defaults = ", ".join(["%s='%s'" % var for var in _vars.iteritems()]) |
|
9 | 9 | }} |
|
10 | ||
|
11 | if __name__ == '__main__': | |
|
10 | 12 | main({{ defaults }}) |
@@ -26,4 +26,5 b' conf_dict = ConfigLoader(conf_path).pars' | |||
|
26 | 26 | |
|
27 | 27 | # migrate supports passing url as an existing Engine instance (since 0.6.0) |
|
28 | 28 | # usage: migrate -c path/to/config.ini COMMANDS |
|
29 | if __name__ == '__main__': | |
|
29 | 30 | main(url=engine_from_config(conf_dict), repository=migrations.__path__[0],{{ defaults }}) |
@@ -90,9 +90,7 b' class Collection(pathed.Pathed):' | |||
|
90 | 90 | return max([VerNum(0)] + self.versions.keys()) |
|
91 | 91 | |
|
92 | 92 | def _next_ver_num(self, use_timestamp_numbering): |
|
93 | print use_timestamp_numbering | |
|
94 | 93 | if use_timestamp_numbering == True: |
|
95 | print "Creating new timestamp version!" | |
|
96 | 94 | return VerNum(int(datetime.utcnow().strftime('%Y%m%d%H%M%S'))) |
|
97 | 95 | else: |
|
98 | 96 | return self.latest + 1 |
@@ -21,7 +21,7 b' def upgrade(migrate_engine):' | |||
|
21 | 21 | #========================================================================== |
|
22 | 22 | # Add table `groups`` |
|
23 | 23 | #========================================================================== |
|
24 | from rhodecode.lib.dbmigrate.schema.db_1_2_0 import Group | |
|
24 | from rhodecode.lib.dbmigrate.schema.db_1_2_0 import RepoGroup as Group | |
|
25 | 25 | Group().__table__.create() |
|
26 | 26 | |
|
27 | 27 | #========================================================================== |
General Comments 0
You need to be logged in to leave comments.
Login now