diff -r ba5615dcf132 ckan/model/__init__.py
a
|
b
|
|
42 | 42 | class Repository(vdm.sqlalchemy.Repository): |
43 | 43 | migrate_repository = ckan.migration.__path__[0] |
44 | 44 | |
| 45 | inited = False |
| 46 | |
45 | 47 | def init_db(self, conditional=False): |
46 | | if conditional: |
47 | | already_done = Session.connection()\ |
48 | | .engine.has_table("user") |
49 | | else: |
50 | | already_done = False |
51 | | if not already_done: |
| 48 | #sqlite database needs to be recreted each time as the memory database |
| 49 | #is lost. |
| 50 | if not self.inited or self.metadata.bind.name == 'sqlite': |
52 | 51 | super(Repository, self).init_db() |
| 52 | |
| 53 | self.session.rollback() |
| 54 | self.session.remove() |
53 | 55 | self.add_initial_data() |
54 | 56 | |
55 | 57 | def add_initial_data(self): |
… |
… |
|
98 | 100 | else: |
99 | 101 | tables = reversed(metadata.sorted_tables) |
100 | 102 | for table in tables: |
101 | | connection.execute('drop table "%s"' % table.name) |
| 103 | connection.execute('delete from "%s"' % table.name) |
102 | 104 | self.session.commit() |
103 | | #self.add_initial_data() |
| 105 | self.add_initial_data() |
104 | 106 | |
105 | 107 | def setup_migration_version_control(self, version=None): |
106 | 108 | import migrate.versioning.exceptions |
diff -r ba5615dcf132 ckan/tests/__init__.py
a
|
b
|
|
56 | 56 | cmd.run([config_path]) |
57 | 57 | |
58 | 58 | import ckan.model as model |
59 | | model.repo.rebuild_db() |
| 59 | model.repo.init_db() |
| 60 | |
| 61 | #make sure that the database is droped and recreated first |
| 62 | #so that any schema changes will be made. |
| 63 | model.repo.metadata.drop_all(bind=model.repo.metadata.bind) |
| 64 | model.repo.init_db() |
| 65 | #tell repo it does not need to drop and craete any more |
| 66 | model.repo.inited = True |
60 | 67 | |
61 | 68 | class BaseCase(object): |
62 | 69 | |