Skip to content

Commit

Permalink
Dev More database field type fixes
Browse files Browse the repository at this point in the history
Dev I assume they don't need a special DB update as there are no known problems, yet
  • Loading branch information
c-schmitz committed May 23, 2019
1 parent 64ba8d4 commit c0c0c6e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 36 deletions.
65 changes: 40 additions & 25 deletions application/helpers/update/updatedb_helper.php
Expand Up @@ -16,7 +16,22 @@
- Never use models in the upgrade process - never ever!
- Use the provided addColumn, alterColumn, dropPrimaryKey etc. functions where applicable - they ensure cross-DB compatibility
- Never use foreign keys
- Do not use fancy database field types (like mediumtext, timestamp, etc) - only use the ones provided by Yii
- Do not use fancy database field types (like mediumtext, timestamp, etc) - only use the ones provided by Yii which are:
pk: auto-incremental primary key type (“int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY”).
string: string type (“varchar(255)”).
text: a long string type (“text”).
integer: integer type (“int(11)”).
boolean: boolean type (“tinyint(1)”).
float: float number type (“float”).
decimal: decimal number type (“decimal”).
datetime: datetime type (“datetime”).
timestamp: timestamp type (“timestamp”).
time: time type (“time”).
date: date type (“date”).
binary: binary data type (“blob”).

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle May 23, 2019

Collaborator

Can we add longbinary ? Since we added it in the 3 Schema ?

These are case-sensitive - only use lowercase!
- If you want to use database functions make sure they exist on all three supported database types
- Always prefix key names by using curly brackets {{ }}
Expand Down Expand Up @@ -596,7 +611,7 @@ function db_upgrade_all($iOldDBVersion, $bSilent = false)
if ($iOldDBVersion < 150)
{
$oTransaction = $oDB->beginTransaction();
addColumn('{{questions}}','relevance','TEXT');
addColumn('{{questions}}','relevance','text');
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>150),"stg_name='DBVersion'");
$oTransaction->commit();
}
Expand Down Expand Up @@ -700,7 +715,7 @@ function db_upgrade_all($iOldDBVersion, $bSilent = false)
}

addPrimaryKey('sessions', array('id'));
addColumn('{{surveys_languagesettings}}','surveyls_attributecaptions',"TEXT");
addColumn('{{surveys_languagesettings}}','surveyls_attributecaptions',"text");
addColumn('{{surveys}}','sendconfirmation',"string(1) default 'Y'");

upgradeSurveys156();
Expand Down Expand Up @@ -1730,7 +1745,7 @@ function db_upgrade_all($iOldDBVersion, $bSilent = false)
'tid' => 'pk',
'name' => 'string(128)',
'description' => 'text',
'active' => 'int DEFAULT 0',
'active' => 'integer DEFAULT 0',
'settings' => 'text',
'permission' => 'string(128) NOT NULL',
'permission_grade' => 'string(128) NOT NULL'
Expand All @@ -1739,7 +1754,7 @@ function db_upgrade_all($iOldDBVersion, $bSilent = false)
$oDB->createCommand()->createTable(
'{{tutorial_entries}}', [
'teid' => 'pk',
'tid' => 'int NOT NULL',
'tid' => 'integer NOT NULL',
'title' => 'text',
'content' => 'text',
'settings' => 'text'
Expand Down Expand Up @@ -2507,18 +2522,18 @@ function resetTutorials337($oDB)
function upgrade333($oDB)
{
$oDB->createCommand()->createTable('{{map_tutorial_users}}', array(
'tid' => 'int NOT NULL',
'uid' => 'int NOT NULL',
'taken' => 'int DEFAULT 1',
'tid' => 'integer NOT NULL',
'uid' => 'integer NOT NULL',
'taken' => 'integer DEFAULT 1',
));

$oDB->createCommand()->addPrimaryKey('{{map_tutorial_users_pk}}', '{{map_tutorial_users}}', ['uid', 'tid']);

$oDB->createCommand()->createTable('{{tutorial_entry_relation}}', array(
'teid' => 'int NOT NULL',
'tid' => 'int NOT NULL',
'uid' => 'int DEFAULT NULL',
'sid' => 'int DEFAULT NULL',
'teid' => 'integer NOT NULL',
'tid' => 'integer NOT NULL',
'uid' => 'integer DEFAULT NULL',
'sid' => 'integer DEFAULT NULL',
));

$oDB->createCommand()->addPrimaryKey('{{tutorial_entry_relation_pk}}', '{{tutorial_entry_relation}}', ['teid', 'tid']);
Expand All @@ -2527,7 +2542,7 @@ function upgrade333($oDB)
$oDB->createCommand()->createIndex('{{idx1_tutorials}}', '{{tutorials}}', 'name', true);

$oDB->createCommand()->dropColumn('{{tutorial_entries}}', 'tid');
$oDB->createCommand()->addColumn('{{tutorial_entries}}', 'ordering', 'int');
$oDB->createCommand()->addColumn('{{tutorial_entries}}', 'ordering', 'integer');

}

Expand Down Expand Up @@ -2644,14 +2659,14 @@ function transferPasswordFieldToText($oDB)
switch ($oDB->getDriverName()) {
case 'mysql':
case 'mysqli':
$oDB->createCommand()->alterColumn('{{users}}', 'password', 'TEXT NOT NULL');
$oDB->createCommand()->alterColumn('{{users}}', 'password', 'text NOT NULL');
break;
case 'pgsql':

$userPasswords = $oDB->createCommand()->select(['uid', "encode(password::bytea, 'escape') as password"])->from('{{users}}')->queryAll();

$oDB->createCommand()->renameColumn('{{users}}', 'password', 'password_blob');
$oDB->createCommand()->addColumn('{{users}}', 'password', "TEXT NOT NULL DEFAULT 'nopw'");
$oDB->createCommand()->addColumn('{{users}}', 'password', "text NOT NULL DEFAULT 'nopw'");

foreach ($userPasswords as $userArray) {
$oDB->createCommand()->update('{{users}}', ['password' => $userArray['password']], 'uid=:uid', [':uid'=> $userArray['uid']]);
Expand Down Expand Up @@ -2826,13 +2841,13 @@ function upgradeTemplateTables304($oDB)
'author' => 'string(150) DEFAULT NULL',
'author_email' => 'string DEFAULT NULL',
'author_url' => 'string DEFAULT NULL',
'copyright' => 'TEXT',
'license' => 'TEXT',
'copyright' => 'text',
'license' => 'text',
'version' => 'string(45) DEFAULT NULL',
'api_version' => 'string(45) NOT NULL',
'view_folder' => 'string(45) NOT NULL',
'files_folder' => 'string(45) NOT NULL',
'description' => 'TEXT',
'description' => 'text',
'last_update' => 'datetime DEFAULT NULL',
'owner_id' => 'integer DEFAULT NULL',
'extends_template_name' => 'string(150) DEFAULT NULL',
Expand Down Expand Up @@ -2909,14 +2924,14 @@ function upgradeTemplateTables304($oDB)
'sid' => 'integer DEFAULT NULL',
'gsid' => 'integer DEFAULT NULL',
'uid' => 'integer DEFAULT NULL',
'files_css' => 'TEXT',
'files_js' => 'TEXT',
'files_print_css' => 'TEXT',
'options' => 'TEXT',
'files_css' => 'text',
'files_js' => 'text',
'files_print_css' => 'text',
'options' => 'text',
'cssframework_name' => 'string(45) DEFAULT NULL',
'cssframework_css' => 'TEXT',
'cssframework_js' => 'TEXT',
'packages_to_load' => 'TEXT',
'cssframework_css' => 'text',
'cssframework_js' => 'text',
'packages_to_load' => 'text',
));

// Add global configuration for Advanced Template
Expand Down
22 changes: 11 additions & 11 deletions installer/create-database.php
Expand Up @@ -274,7 +274,7 @@ function createDatabase($oDB){
$oDB->createCommand()->createTable('{{plugins}}', array(
'id' => "pk",
'name' => "string(50) NOT NULL",
'active' => "int NOT NULL default 0",
'active' => "integer NOT NULL default 0",
'version' => "string(32) NULL",
));

Expand Down Expand Up @@ -536,7 +536,7 @@ function createDatabase($oDB){
'ipaddr' => "string(1) NOT NULL default 'N'",
'refurl' => "string(1) NOT NULL default 'N'",
'datecreated' => "datetime",
'showsurveypolicynotice' => 'int DEFAULT 0',
'showsurveypolicynotice' => 'integer DEFAULT 0',
'publicstatistics' => "string(1) NOT NULL default 'N'",
'publicgraphs' => "string(1) NOT NULL default 'N'",
'listpublic' => "string(1) NOT NULL default 'N'",
Expand Down Expand Up @@ -733,7 +733,7 @@ function createDatabase($oDB){
'title' => 'string(192)',
'icon' => 'string(64)',
'description' => 'text',
'active' => 'int DEFAULT 0',
'active' => 'integer DEFAULT 0',
'settings' => 'text',
'permission' => 'string(128) NOT NULL',
'permission_grade' => 'string(128) NOT NULL'
Expand All @@ -743,19 +743,19 @@ function createDatabase($oDB){

//tutorial user mapping
$oDB->createCommand()->createTable('{{map_tutorial_users}}', array(
'tid' => 'int NOT NULL',
'uid' => 'int NOT NULL',
'taken' => 'int DEFAULT 1',
'tid' => 'integer NOT NULL',
'uid' => 'integer NOT NULL',
'taken' => 'integer DEFAULT 1',
));

$oDB->createCommand()->addPrimaryKey('{{map_tutorial_users_pk}}', '{{map_tutorial_users}}', ['uid','tid']);

//tutorial entry groups
$oDB->createCommand()->createTable('{{tutorial_entry_relation}}', array(
'teid' => 'int NOT NULL',
'tid' => 'int NOT NULL',
'uid' => 'int NULL',
'sid' => 'int NULL',
'teid' => 'integer NOT NULL',
'tid' => 'integer NOT NULL',
'uid' => 'integer NULL',
'sid' => 'integer NULL',
));

$oDB->createCommand()->addPrimaryKey('{{tutorial_entry_relation_pk}}', '{{tutorial_entry_relation}}', ['teid','tid']);
Expand All @@ -766,7 +766,7 @@ function createDatabase($oDB){
$oDB->createCommand()->createTable(
'{{tutorial_entries}}',[
'teid' => 'pk',
'ordering' => 'int',
'ordering' => 'integer',
'title' => 'text',
'content' => 'text',
'settings' => 'text'
Expand Down

0 comments on commit c0c0c6e

Please sign in to comment.