def action_reset(self, options, args): """Reset the model tables. Use with care, will drop all the tables. """ if not options.force: ans = raw_input(""" Be careful, all the tables of database %r will be dropped. All the data stored in the database will be lost too. Are you sure about this action? (y/N): """ % settings.DATABASE_NAME) if ans.lower() != 'y': return models, __pending = self.get_models() models.reverse() try: for model in models: if options.verbose: print "Drop table %r" % model._meta.table database.drop_table(model) except: database.rollback() raise else: database.commit() self.action_sync(options, args)
def action_clear(self, options, args): """Clear all the data from database. """ if not options.force: ans = raw_input( """ Be careful, all the data from database %r will be cleared. Are you sure about this action? (y/N): """ % settings.DATABASE_NAME ) if ans.lower() != "y": return models, __pending = self.get_models() models.reverse() try: for model in models: if options.verbose: print "Clear table %r" % model._meta.table model.all().delete() except: database.rollback() raise else: database.commit()
def action_sync(self, options, args): """Create the database tables for all the INSTALLED_PACKAGES whose tables haven't been created yet. """ models, __pending = self.get_models() try: for model in models: if options.verbose: print "Sync table %r" % (model._meta.table) database.create_table(model) except: database.rollback() raise else: database.commit()
def action_clear(self, options, args): """Clear all the data from database. """ if not options.force: ans = raw_input(""" Be careful, all the data from database %r will be cleared. Are you sure about this action? (y/N): """ % settings.DATABASE_NAME) if ans.lower() != 'y': return models, __pending = self.get_models() models.reverse() try: for model in models: if options.verbose: print "Clear table %r" % model._meta.table model.all().delete() except: database.rollback() raise else: database.commit()