Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update upgrade process to support churchinfo 1.3.1 #6896

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ChurchCRM/Service/SystemService.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function setConfigurationSetting($settingName, $settingValue): void
public static function getDBVersion()
{
$connection = Propel::getConnection();
$query = 'select * from version_ver order by ver_update_end desc limit 1';
$query = 'select * from version_ver order by ver_id desc limit 1';
$statement = $connection->prepare($query);
$statement->execute();
$results = $statement->fetchAll(\PDO::FETCH_ASSOC);
Expand Down
3 changes: 2 additions & 1 deletion src/mysql/upgrade.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"pre-2.0.0": {
"versions": [
"1.2.14",
"1.3.0"
"1.3.0",
"1.3.1"
],
"scripts": [
"/mysql/upgrade/2.0.0.sql"
Expand Down
9 changes: 7 additions & 2 deletions src/mysql/upgrade/2.0.0.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
DELETE FROM config_cfg
WHERE cfg_id IN (2, 4, 15, 17, 24, 32, 35, 999);
alter table version_ver add `ver_update_start` datetime DEFAULT NULL;

alter table version_ver add `ver_update_end` datetime DEFAULT NULL;

alter table version_ver drop column `ver_date`;

Comment on lines +1 to +5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the same spirit as #6831 , we should make our migrations replayable to avoid issues on re-run

DELETE FROM config_cfg WHERE cfg_id IN (2, 4, 15, 17, 24, 32, 35, 999);

INSERT IGNORE INTO config_cfg (cfg_id, cfg_name, cfg_value, cfg_type, cfg_default, cfg_tooltip, cfg_section, cfg_category)
VALUES
Expand Down
12 changes: 2 additions & 10 deletions src/mysql/upgrade/2.10.0.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
IF NOT EXISTS (
SELECT NULL
FROM INFORMATION_SCHEMA.COLUMNS
WHERE
table_name = 'events_event' AND
column_name = 'event_publicly_visible'
) THEN
ALTER TABLE `events_event`
ADD COLUMN `event_publicly_visible` BOOLEAN DEFAULT FALSE AFTER `event_grpid`;
END IF;
ALTER TABLE events_event
ADD COLUMN event_publicly_visible BOOLEAN DEFAULT FALSE AFTER event_grpid;
2 changes: 1 addition & 1 deletion src/mysql/upgrade/2.3.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ MODIFY `cfg_type` ENUM('text','number','date','boolean','textarea','json','choic

ALTER TABLE `config_cfg`
ADD COLUMN
`cfg_data` text default NULL AFTER `cfg_order`;
`cfg_data` text default NULL;

Update `config_cfg` set
`cfg_data` = '{"Choices":["smtp","SendMail"]}',
Expand Down
28 changes: 3 additions & 25 deletions src/mysql/upgrade/2.4.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,9 @@ MODIFY `cfg_type` ENUM('text','number','date','boolean','textarea','json','choic
INSERT IGNORE INTO `config_cfg` (`cfg_id`, `cfg_name`, `cfg_value`, `cfg_type`, `cfg_default`, `cfg_tooltip`, `cfg_section`) VALUES
(1047, 'sChurchCountry', 'United States', 'country', '', 'Church Country', 'ChurchInfoReport');

/* make drop column if exists procedure */
DROP PROCEDURE IF EXISTS DropColumnIfExists;
CREATE PROCEDURE DropColumnIfExists(IN tableName VARCHAR(255), IN columnName VARCHAR(255))
BEGIN
DECLARE columnExists INT;

-- Check if the column exists
SELECT COUNT(*)
INTO columnExists
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = tableName AND column_name = columnName;

-- Drop the column if it exists
IF columnExists > 0 THEN
SET @dropColumnQuery = CONCAT('ALTER TABLE `', tableName, '` DROP COLUMN `', columnName, '`');
PREPARE stmt FROM @dropColumnQuery;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
END;

CALL DropColumnIfExists('user_usr', 'usr_BaseFontSize');
CALL DropColumnIfExists('user_usr', 'usr_Communication');
CALL DropColumnIfExists('user_usr', 'usr_Workspacewidth');
alter table user_usr drop column `usr_BaseFontSize`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this edited?

alter table user_usr drop column `usr_Communication`;
alter table user_usr drop column `usr_Workspacewidth`;

ALTER TABLE `user_usr`
CHANGE COLUMN `usr_NeedPasswordChange` `usr_NeedPasswordChange` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1' COMMENT '' ,
Expand All @@ -41,4 +20,3 @@ CHANGE COLUMN `usr_ManageGroups` `usr_ManageGroups` TINYINT(1) UNSIGNED NOT NULL
CHANGE COLUMN `usr_Finance` `usr_Finance` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0' COMMENT '' ,
CHANGE COLUMN `usr_Admin` `usr_Admin` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0' COMMENT '' ;

DROP PROCEDURE IF EXISTS DropColumnIfExists;
35 changes: 5 additions & 30 deletions src/mysql/upgrade/2.6.0.sql
Original file line number Diff line number Diff line change
@@ -1,32 +1,7 @@
DELETE FROM config_cfg WHERE cfg_value = cfg_default;

/* make drop column if exists procedure */
DROP PROCEDURE IF EXISTS DropColumnIfExists;
CREATE PROCEDURE DropColumnIfExists(IN tableName VARCHAR(255), IN columnName VARCHAR(255))
BEGIN
DECLARE columnExists INT;

-- Check if the column exists
SELECT COUNT(*)
INTO columnExists
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = tableName AND column_name = columnName;

-- Drop the column if it exists
IF columnExists > 0 THEN
SET @dropColumnQuery = CONCAT('ALTER TABLE `', tableName, '` DROP COLUMN `', columnName, '`');
PREPARE stmt FROM @dropColumnQuery;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
END;

CALL DropColumnIfExists('config_cfg', 'cfg_type');
CALL DropColumnIfExists('config_cfg', 'cfg_default');
CALL DropColumnIfExists('config_cfg', 'cfg_tooltip');
CALL DropColumnIfExists('config_cfg', 'cfg_section');
CALL DropColumnIfExists('config_cfg', 'cfg_category');
CALL DropColumnIfExists('config_cfg', 'cfg_order');
CALL DropColumnIfExists('config_cfg', 'cfg_data');

DROP PROCEDURE IF EXISTS DropColumnIfExists;
alter table config_cfg drop column `cfg_type`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this edited?

alter table config_cfg drop column `cfg_tooltip`;
alter table config_cfg drop column `cfg_section`;
alter table config_cfg drop column `cfg_category`;
alter table config_cfg drop column `cfg_data`;
29 changes: 3 additions & 26 deletions src/mysql/upgrade/2.7.0.sql
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
/* make add column if not exists procedure */
DROP PROCEDURE IF EXISTS AddColumnIfNotExists;
CREATE PROCEDURE AddColumnIfNotExists(IN tableName VARCHAR(255), IN columnName VARCHAR(255), IN columnDesc VARCHAR(255))
BEGIN
DECLARE columnExists INT;

-- Check if the column exists
SELECT COUNT(*)
INTO columnExists
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = tableName AND column_name = columnName;

-- Add the column if it doesn't exist
IF columnExists = 0 THEN
SET @addColumnQuery = CONCAT('ALTER TABLE `', tableName, '` ADD COLUMN `', columnName, '` ', columnDesc);
PREPARE stmt FROM @addColumnQuery;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
END;

CALL AddColumnIfNotExists('group_grp', 'grp_active', 'BOOLEAN NOT NULL DEFAULT 1 AFTER grp_hasSpecialProps');
CALL AddColumnIfNotExists('group_grp', 'grp_include_email_export', 'BOOLEAN NOT NULL DEFAULT 1 AFTER grp_active');
ALTER TABLE group_grp ADD grp_active BOOLEAN DEFAULT 1 NOT NULL AFTER grp_hasSpecialProps;
ALTER TABLE group_grp ADD grp_include_email_export BOOLEAN DEFAULT 1 NOT NULL AFTER grp_active;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this edited?


ALTER TABLE queryparameteroptions_qpo
MODIFY qpo_Value VARCHAR(255) NOT NULL DEFAULT '';
Expand All @@ -35,6 +14,4 @@ DELETE FROM userconfig_ucfg where ucfg_name = "sFromEmailAddress";
DELETE FROM userconfig_ucfg where ucfg_name = "sFromName";
DELETE FROM userconfig_ucfg where ucfg_name = "bSendPHPMail";

CALL AddColumnIfNotExists('event_attend', 'attend_id', 'INT PRIMARY KEY AUTO_INCREMENT FIRST');

DROP PROCEDURE IF EXISTS AddColumnIfNotExists;
ALTER TABLE event_attend ADD COLUMN attend_id INT PRIMARY KEY AUTO_INCREMENT FIRST;
26 changes: 2 additions & 24 deletions src/mysql/upgrade/2.8.0.sql
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
/* make add column if not exists procedure */
DROP PROCEDURE IF EXISTS AddColumnIfNotExists;
CREATE PROCEDURE AddColumnIfNotExists(IN tableName VARCHAR(255), IN columnName VARCHAR(255), IN columnDesc VARCHAR(255))
BEGIN
DECLARE columnExists INT;

-- Check if the column exists
SELECT COUNT(*)
INTO columnExists
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = tableName AND column_name = columnName;

-- Add the column if it doesn't exist
IF columnExists = 0 THEN
SET @addColumnQuery = CONCAT('ALTER TABLE `', tableName, '` ADD COLUMN `', columnName, '` ', columnDesc);
PREPARE stmt FROM @addColumnQuery;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
END;

DROP TABLE IF EXISTS `kioskdevice_kdev`;
CREATE TABLE `kioskdevice_kdev` (
Expand All @@ -44,8 +24,8 @@ CREATE TABLE `kioskassginment_kasm` (
UNIQUE KEY `kasm_ID` (`kasm_ID`)
) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci;

CALL AddColumnIfNotExists('events_event', 'event_grpid', 'mediumint(9) AFTER event_typename');
CALL AddColumnIfNotExists('event_types', 'type_grpid', 'mediumint(9) AFTER type_active');
ALTER TABLE events_event ADD COLUMN event_grpid mediumint(9) AFTER event_typename;
ALTER TABLE event_types ADD COLUMN type_grpid mediumint(9) AFTER type_active;

ALTER TABLE `tokens` CHANGE COLUMN `type` `type` VARCHAR(50);

Expand Down Expand Up @@ -76,5 +56,3 @@ update config_cfg set cfg_name = 'iChurchLongitude' where cfg_name = 'nChurchLon

/** array **/
update config_cfg set cfg_name = 'aDisallowedPasswords' where cfg_name = 'sDisallowedPasswords';

DROP PROCEDURE IF EXISTS AddColumnIfNotExists;
26 changes: 2 additions & 24 deletions src/mysql/upgrade/2.9.0.sql
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
/* make add column if not exists procedure */
DROP PROCEDURE IF EXISTS AddColumnIfNotExists;
CREATE PROCEDURE AddColumnIfNotExists(IN tableName VARCHAR(255), IN columnName VARCHAR(255), IN columnDesc VARCHAR(255))
BEGIN
DECLARE columnExists INT;

-- Check if the column exists
SELECT COUNT(*)
INTO columnExists
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = tableName AND column_name = columnName;

-- Add the column if it doesn't exist
IF columnExists = 0 THEN
SET @addColumnQuery = CONCAT('ALTER TABLE `', tableName, '` ADD COLUMN `', columnName, '` ', columnDesc);
PREPARE stmt FROM @addColumnQuery;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
END;

-- --NOTE-- removed in 4.4.0 so commenting out --
-- CALL AddColumnIfNotExists('person_per', 'per_FacebookID', 'bigint(20) unsigned default NULL AFTER per_Flags');
CALL AddColumnIfNotExists('person_per', 'per_Twitter', 'varchar(50) default NULL AFTER per_Flags');
CALL AddColumnIfNotExists('person_per', 'per_LinkedIn', 'varchar(50) default NULL AFTER per_Twitter');
ALTER TABLE person_per ADD COLUMN per_Twitter varchar(50) default NULL AFTER per_Flags;
ALTER TABLE person_per ADD COLUMN per_LinkedIn varchar(50) default NULL AFTER per_Twitter;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this edited?


ALTER TABLE person_custom_master
ADD PRIMARY KEY (custom_Field);
Expand Down Expand Up @@ -64,5 +44,3 @@ CREATE TABLE `church_location_role` (
`role_title` INT NOT NULL, #Thi
PRIMARY KEY (`location_id`, `role_id`)
) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_unicode_ci;

DROP PROCEDURE IF EXISTS AddColumnIfNotExists;
31 changes: 4 additions & 27 deletions src/mysql/upgrade/3.0.0.sql
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
/* make add column if not exists procedure */
DROP PROCEDURE IF EXISTS AddColumnIfNotExists;
CREATE PROCEDURE AddColumnIfNotExists(IN tableName VARCHAR(255), IN columnName VARCHAR(255), IN columnDesc VARCHAR(255))
BEGIN
DECLARE columnExists INT;

-- Check if the column exists
SELECT COUNT(*)
INTO columnExists
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = tableName AND column_name = columnName;

-- Add the column if it doesn't exist
IF columnExists = 0 THEN
SET @addColumnQuery = CONCAT('ALTER TABLE `', tableName, '` ADD COLUMN `', columnName, '` ', columnDesc);
PREPARE stmt FROM @addColumnQuery;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
END;

CALL AddColumnIfNotExists('events_event', 'location_id', 'INT DEFAULT NULL AFTER `event_typename`');
CALL AddColumnIfNotExists('events_event', 'primary_contact_person_id', 'INT DEFAULT NULL AFTER `location_id`');
CALL AddColumnIfNotExists('events_event', 'secondary_contact_person_id', 'INT DEFAULT NULL AFTER `primary_contact_person_id`');
CALL AddColumnIfNotExists('events_event', 'event_url', 'text DEFAULT NULL AFTER `secondary_contact_person_id`');
ALTER TABLE events_event ADD COLUMN location_id INT DEFAULT NULL AFTER `event_typename`;
ALTER TABLE events_event ADD COLUMN primary_contact_person_id INT DEFAULT NULL AFTER `location_id`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this edited?

ALTER TABLE events_event ADD COLUMN secondary_contact_person_id INT DEFAULT NULL AFTER `primary_contact_person_id`;
ALTER TABLE events_event ADD COLUMN event_url text DEFAULT NULL AFTER `secondary_contact_person_id`;

DROP TABLE IF EXISTS `event_audience`;
# This is a join-table to link an event with a prospective audience for the purpose of advertising / outreach.
Expand Down Expand Up @@ -69,5 +48,3 @@ CREATE TABLE `menu_links` (
`linkOrder` INT NOT NULL,
PRIMARY KEY (`linkId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP PROCEDURE IF EXISTS AddColumnIfNotExists;
29 changes: 3 additions & 26 deletions src/mysql/upgrade/4.0.0-TwoFactorAuth.sql
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
/* make add column if not exists procedure */
DROP PROCEDURE IF EXISTS AddColumnIfNotExists;
CREATE PROCEDURE AddColumnIfNotExists(IN tableName VARCHAR(255), IN columnName VARCHAR(255), IN columnDesc VARCHAR(255))
BEGIN
DECLARE columnExists INT;

-- Check if the column exists
SELECT COUNT(*)
INTO columnExists
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = tableName AND column_name = columnName;

-- Add the column if it doesn't exist
IF columnExists = 0 THEN
SET @addColumnQuery = CONCAT('ALTER TABLE `', tableName, '` ADD COLUMN `', columnName, '` ', columnDesc);
PREPARE stmt FROM @addColumnQuery;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
END;

CALL AddColumnIfNotExists('user_usr', 'usr_TwoFactorAuthSecret', 'VARCHAR(255) NULL AFTER `usr_Canvasser`');
CALL AddColumnIfNotExists('user_usr', 'usr_TwoFactorAuthLastKeyTimestamp', 'INT NULL AFTER `usr_TwoFactorAuthSecret`');
CALL AddColumnIfNotExists('user_usr', 'usr_TwoFactorAuthRecoveryCodes', 'TEXT NULL AFTER `usr_TwoFactorAuthLastKeyTimestamp');

DROP PROCEDURE IF EXISTS AddColumnIfNotExists;
ALTER TABLE user_usr ADD COLUMN usr_TwoFactorAuthSecret VARCHAR(255) NULL AFTER `usr_Canvasser`;
ALTER TABLE user_usr ADD COLUMN usr_TwoFactorAuthLastKeyTimestamp INT NULL AFTER `usr_TwoFactorAuthSecret`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this edited?

ALTER TABLE user_usr ADD COLUMN usr_TwoFactorAuthRecoveryCodes TEXT NULL AFTER `usr_TwoFactorAuthLastKeyTimestamp`;
Loading
Loading