def delete(self, id, **kwargs): """Delete a PlayerPref. After deleting the PlayerPref, cleans up the players table, ensuring that each Player class is represented--if the deleted PlayerPref is the last example of that Player class, creates a new disabled PlayerPref for that Player class with the default settings. :param id: Player ID. :type id: ``int`` :returns: Redirect back to :meth:`index` after successful delete. """ player = fetch_row(PlayerPrefs, id) DBSession.delete(player) DBSession.flush() cleanup_players_table() redirect(action='index', id=None)
def setup_app(command, conf, vars): """Called by ``paster setup-app``. This script is responsible for: * Creating the initial database schema and loading default data. * Executing any migrations necessary to bring an existing database up-to-date. Your data should be safe but, as always, be sure to make backups before using this. * Re-creating the default database for every run of the test suite. XXX: All your data will be lost IF you run the test suite with a config file named 'test.ini'. Make sure you have this configured to a different database than in your usual deployment.ini or development.ini file because all database tables are dropped a and recreated every time this script runs. XXX: If you are upgrading from MediaCore v0.7.2 or v0.8.0, run whichever one of these that applies: ``python batch-scripts/upgrade/upgrade_from_v072.py deployment.ini`` ``python batch-scripts/upgrade/upgrade_from_v080.py deployment.ini`` XXX: For search to work, we depend on a number of MySQL triggers which copy the data from our InnoDB tables to a MyISAM table for its fulltext indexing capability. Triggers can only be installed with a mysql superuser like root, so you must run the setup_triggers.sql script yourself. """ if pylons.test.pylonsapp: # NOTE: This extra filename check may be unnecessary, the example it is # from did not check for pylons.test.pylonsapp. Leaving it in for now # to make it harder for someone to accidentally delete their database. filename = os.path.split(conf.filename)[-1] if filename == 'test.ini': log.info('Dropping existing tables...') metadata.drop_all(checkfirst=True) drop_version_control(conf.local_conf['sqlalchemy.url'], migrate_repository) else: # Don't reload the app if it was loaded under the testing environment config = load_environment(conf.global_conf, conf.local_conf) # Create the migrate_version table if it doesn't exist. # If the table doesn't exist, we assume the schema was just setup # by this script and therefore must be the latest version. latest_version = version(migrate_repository) try: version_control(conf.local_conf['sqlalchemy.url'], migrate_repository, version=latest_version) except DatabaseAlreadyControlledError: log.info('Running any new migrations, if there are any') upgrade(conf.local_conf['sqlalchemy.url'], migrate_repository, version=latest_version) else: log.info('Initializing new database with version %r' % latest_version) metadata.create_all(bind=DBSession.bind, checkfirst=True) add_default_data() cleanup_players_table(enabled=True) # Save everything, along with the dummy data if applicable DBSession.commit() log.info('Generating appearance.css from your current settings') settings = DBSession.query(Setting.key, Setting.value) generate_appearance_css(settings, cache_dir=conf['cache_dir']) log.info('Successfully setup')
def setup_app(command, conf, vars): """Called by ``paster setup-app``. This script is responsible for: * Creating the initial database schema and loading default data. * Executing any migrations necessary to bring an existing database up-to-date. Your data should be safe but, as always, be sure to make backups before using this. * Re-creating the default database for every run of the test suite. XXX: All your data will be lost IF you run the test suite with a config file named 'test.ini'. Make sure you have this configured to a different database than in your usual deployment.ini or development.ini file because all database tables are dropped a and recreated every time this script runs. XXX: If you are upgrading from MediaCore v0.7.2 or v0.8.0, run whichever one of these that applies: ``python batch-scripts/upgrade/upgrade_from_v072.py deployment.ini`` ``python batch-scripts/upgrade/upgrade_from_v080.py deployment.ini`` XXX: For search to work, we depend on a number of MySQL triggers which copy the data from our InnoDB tables to a MyISAM table for its fulltext indexing capability. Triggers can only be installed with a mysql superuser like root, so you must run the setup_triggers.sql script yourself. """ config = load_environment(conf.global_conf, conf.local_conf) plugin_manager = config["pylons.app_globals"].plugin_mgr mediacore_migrator = MediaCoreMigrator.from_config(conf, log=log) engine = metadata.bind db_connection = engine.connect() # simplistic check to see if MediaCore tables are present, just check for # the media_files table and assume that all other tables are there as well from mediacore.model.media import media_files mediacore_tables_exist = engine.dialect.has_table(db_connection, media_files.name) run_migrations = True if not mediacore_tables_exist: head_revision = mediacore_migrator.head_revision() log.info("Initializing new database with version %r" % head_revision) metadata.create_all(bind=DBSession.bind, checkfirst=True) mediacore_migrator.init_db(revision=head_revision) run_migrations = False add_default_data() for migrator in plugin_manager.migrators(): migrator.init_db() events.Environment.database_initialized() elif not mediacore_migrator.migrate_table_exists(): log.error( "No migration table found, probably your MediaCore install " "is too old (< 0.9?). Please upgrade to MediaCore CE 0.9 first." ) raise AssertionError("no migration table found") elif not mediacore_migrator.alembic_table_exists(): alembic_revision = mediacore_migrator.map_migrate_version() mediacore_migrator.stamp(alembic_revision) if run_migrations: mediacore_migrator.migrate_db() for migrator in plugin_manager.migrators(): migrator.migrate_db() events.Environment.database_migrated() cleanup_players_table(enabled=True) # Save everything, along with the dummy data if applicable DBSession.commit() events.Environment.database_ready() log.info("Generating appearance.css from your current settings") settings = DBSession.query(Setting.key, Setting.value) generate_appearance_css(settings, cache_dir=conf["cache_dir"]) log.info("Successfully setup")
def setup_app(command, conf, vars): """Called by ``paster setup-app``. This script is responsible for: * Creating the initial database schema and loading default data. * Executing any migrations necessary to bring an existing database up-to-date. Your data should be safe but, as always, be sure to make backups before using this. * Re-creating the default database for every run of the test suite. XXX: All your data will be lost IF you run the test suite with a config file named 'test.ini'. Make sure you have this configured to a different database than in your usual deployment.ini or development.ini file because all database tables are dropped a and recreated every time this script runs. XXX: If you are upgrading from MediaCore v0.7.2 or v0.8.0, run whichever one of these that applies: ``python batch-scripts/upgrade/upgrade_from_v072.py deployment.ini`` ``python batch-scripts/upgrade/upgrade_from_v080.py deployment.ini`` XXX: For search to work, we depend on a number of MySQL triggers which copy the data from our InnoDB tables to a MyISAM table for its fulltext indexing capability. Triggers can only be installed with a mysql superuser like root, so you must run the setup_triggers.sql script yourself. """ config = load_environment(conf.global_conf, conf.local_conf) plugin_manager = config['pylons.app_globals'].plugin_mgr mediacore_migrator = MediaCoreMigrator.from_config(conf, log=log) engine = metadata.bind db_connection = engine.connect() # simplistic check to see if MediaCore tables are present, just check for # the media_files table and assume that all other tables are there as well from mediacore.model.media import media_files mediacore_tables_exist = engine.dialect.has_table(db_connection, media_files.name) run_migrations = True if not mediacore_tables_exist: head_revision = mediacore_migrator.head_revision() log.info('Initializing new database with version %r' % head_revision) metadata.create_all(bind=DBSession.bind, checkfirst=True) mediacore_migrator.init_db(revision=head_revision) run_migrations = False add_default_data() for migrator in plugin_manager.migrators(): migrator.init_db() events.Environment.database_initialized() elif not mediacore_migrator.migrate_table_exists(): log.error('No migration table found, probably your MediaCore install ' 'is too old (< 0.9?). Please upgrade to MediaCore CE 0.9 first.') raise AssertionError('no migration table found') elif not mediacore_migrator.alembic_table_exists(): alembic_revision = mediacore_migrator.map_migrate_version() mediacore_migrator.stamp(alembic_revision) if run_migrations: mediacore_migrator.migrate_db() for migrator in plugin_manager.migrators(): migrator.migrate_db() events.Environment.database_migrated() cleanup_players_table(enabled=True) # Save everything, along with the dummy data if applicable DBSession.commit() events.Environment.database_ready() log.info('Generating appearance.css from your current settings') settings = DBSession.query(Setting.key, Setting.value) generate_appearance_css(settings, cache_dir=conf['cache_dir']) log.info('Successfully setup')