diff --git a/cli/upgrade.php b/cli/upgrade.php index 8901be5..b200ce8 100755 --- a/cli/upgrade.php +++ b/cli/upgrade.php @@ -1,80 +1,80 @@ #!/usr/bin/php . // allowed only from command line interface isset( $argv[ 0 ] ) or exit( 1 ); // command line arguments $opts = getopt( 'h', [ 'load:', ] ); // load the configuration file require $opts['load'] ?? '../load.php'; // check if the aristocratic title is created safe_alter_table_add_column_after( User::T, User::ARISTOCRATIC_TITLE, 'VARCHAR(16)', User::UID ); // allow some event columns to be NULL $event_columns_allowed_to_be_null = [ Room::ID, Track::ID, Chapter::ID ]; foreach( $event_columns_allowed_to_be_null as $event_column_allowed_to_be_null ) { query( sprintf( "ALTER TABLE %s MODIFY COLUMN %s int(10) unsigned", T( Event::T ), $event_column_allowed_to_be_null ) ); } /** * Check if a table field does not exist * * @param $table string Table name * @param $wanted_field string */ function is_table_field_missing( $table, $wanted_field ) { $fields = query_results( sprintf( 'DESCRIBE %s', T( $table ) ) ); foreach( $fields as $field ) { if( $field->Field === $wanted_field ) { return false; } } return true; } /** * Alter table and add a column * * @param $title string Table name * @param $what string Column name * @param $definition string Column definition * @param $after string Column name */ function safe_alter_table_add_column_after( $table, $what, $definition, $after ) { if( is_table_field_missing( $table, $what ) ) { query( sprintf( 'ALTER TABLE %s ADD COLUMN %s %s AFTER %s', T( $table ), $what, $definition, $after ) ); } } diff --git a/documentation/database/patches/patch-9.sql b/documentation/database/patches/patch-9.sql new file mode 100644 index 0000000..61977ce --- /dev/null +++ b/documentation/database/patches/patch-9.sql @@ -0,0 +1,10 @@ +CREATE TABLE IF NOT EXISTS `{$prefix}option` ( + `option_name` varchar(32) NOT NULL, + `option_value` text NOT NULL, + `option_autoload` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0 or 1' +) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Associative informations'; + +ALTER TABLE `{$prefix}option` + ADD PRIMARY KEY (`option_name`), + ADD KEY `option_autoload` (`option_autoload`) COMMENT 'To speed up filtering by autoload'; +