Mercurial > kallithea
comparison rhodecode/lib/db_manage.py @ 964:84bb5b8b498d beta
changed dev and tests to postgressql for more error proof setup.
Fixed postgresql database wipe
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 27 Jan 2011 21:45:30 +0100 |
parents | 2f83756f3041 |
children | b232a36cc51f |
comparison
equal
deleted
inserted
replaced
962:72f008ed9b18 | 964:84bb5b8b498d |
---|---|
67 if os.path.isfile(db_path): | 67 if os.path.isfile(db_path): |
68 | 68 |
69 self.db_exists = True | 69 self.db_exists = True |
70 if not override: | 70 if not override: |
71 raise Exception('database already exists') | 71 raise Exception('database already exists') |
72 return 'sqlite' | |
73 if self.dburi.startswith('postgresql'): | |
74 self.db_exists = True | |
75 return 'postgresql' | |
76 | |
72 | 77 |
73 def create_tables(self, override=False): | 78 def create_tables(self, override=False): |
74 """Create a auth database | 79 """Create a auth database |
75 """ | 80 """ |
76 | 81 |
77 self.check_for_db(override) | 82 db_type = self.check_for_db(override) |
78 if self.db_exists: | 83 if self.db_exists: |
79 log.info("database exist and it's going to be destroyed") | 84 log.info("database exist and it's going to be destroyed") |
80 if self.tests: | 85 if self.tests: |
81 destroy = True | 86 destroy = True |
82 else: | 87 else: |
83 destroy = ask_ok('Are you sure to destroy old database ? [y/n]') | 88 destroy = ask_ok('Are you sure to destroy old database ? [y/n]') |
84 if not destroy: | 89 if not destroy: |
85 sys.exit() | 90 sys.exit() |
86 if self.db_exists and destroy: | 91 if self.db_exists and destroy: |
87 os.remove(jn(self.root, self.dbname)) | 92 if db_type == 'sqlite': |
93 os.remove(jn(self.root, self.dbname)) | |
94 if db_type == 'postgresql': | |
95 meta.Base.metadata.drop_all() | |
96 | |
88 checkfirst = not override | 97 checkfirst = not override |
89 meta.Base.metadata.create_all(checkfirst=checkfirst) | 98 meta.Base.metadata.create_all(checkfirst=checkfirst) |
90 log.info('Created tables for %s', self.dbname) | 99 log.info('Created tables for %s', self.dbname) |
91 | 100 |
92 | 101 |