pre_schema_upgrade()

最后更新于:2021-11-27 20:17:35

pre_schema_upgrade()

Runs before the schema is upgraded.

源文件

文件: gc-admin/includes/upgrade.php

function pre_schema_upgrade() {
	global $gc_current_db_version, $gcdb;

	// Upgrade versions prior to 2.9.
	if ( $gc_current_db_version < 11557 ) {
		// Delete duplicate options. Keep the option with the highest option_id.
		$gcdb->query( "DELETE o1 FROM $gcdb->options AS o1 JOIN $gcdb->options AS o2 USING (`option_name`) WHERE o2.option_id > o1.option_id" );

		// Drop the old primary key and add the new.
		$gcdb->query( "ALTER TABLE $gcdb->options DROP PRIMARY KEY, ADD PRIMARY KEY(option_id)" );

		// Drop the old option_name index. dbDelta() doesn't do the drop.
		$gcdb->query( "ALTER TABLE $gcdb->options DROP INDEX option_name" );
	}

	// Multisite schema upgrades.
	if ( $gc_current_db_version < 25448 && is_multisite() && gc_should_upgrade_global_tables() ) {

		// Upgrade versions prior to 3.7.
		if ( $gc_current_db_version < 25179 ) {
			// New primary key for signups.
			$gcdb->query( "ALTER TABLE $gcdb->signups ADD signup_id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST" );
			$gcdb->query( "ALTER TABLE $gcdb->signups DROP INDEX domain" );
		}

		if ( $gc_current_db_version < 25448 ) {
			// Convert archived from enum to tinyint.
			$gcdb->query( "ALTER TABLE $gcdb->blogs CHANGE COLUMN archived archived varchar(1) NOT NULL default '0'" );
			$gcdb->query( "ALTER TABLE $gcdb->blogs CHANGE COLUMN archived archived tinyint(2) NOT NULL default 0" );
		}
	}

	// Upgrade versions prior to 4.2.
	if ( $gc_current_db_version < 31351 ) {
		if ( ! is_multisite() && gc_should_upgrade_global_tables() ) {
			$gcdb->query( "ALTER TABLE $gcdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
		}
		$gcdb->query( "ALTER TABLE $gcdb->terms DROP INDEX slug, ADD INDEX slug(slug(191))" );
		$gcdb->query( "ALTER TABLE $gcdb->terms DROP INDEX name, ADD INDEX name(name(191))" );
		$gcdb->query( "ALTER TABLE $gcdb->commentmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
		$gcdb->query( "ALTER TABLE $gcdb->postmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
		$gcdb->query( "ALTER TABLE $gcdb->posts DROP INDEX post_name, ADD INDEX post_name(post_name(191))" );
	}

	// Upgrade versions prior to 4.4.
	if ( $gc_current_db_version < 34978 ) {
		// If compatible termmeta table is found, use it, but enforce a proper index and update collation.
		if ( $gcdb->get_var( "SHOW TABLES LIKE '{$gcdb->termmeta}'" ) && $gcdb->get_results( "SHOW INDEX FROM {$gcdb->termmeta} WHERE Column_name = 'meta_key'" ) ) {
			$gcdb->query( "ALTER TABLE $gcdb->termmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
			maybe_convert_table_to_utf8mb4( $gcdb->termmeta );
		}
	}
}