4 * Upgrading and patching functions of database.
6 * Functions to allow safe database modifications
7 * during upgrading and patches.
9 * Copyright (C) 2008-2012 Rod Roark <rod@sunsetsystems.com>
11 * LICENSE: This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>.
23 * @author Rod Roark <rod@sunsetsystems.com>
24 * @author Brady Miller <brady.g.miller@gmail.com>
25 * @author Teny <teny@zhservices.com>
26 * @author Jerry Padgett <sjpadgett@gmail.com>
27 * @link https://www.open-emr.org
32 * Upgrade or patch the database with a selected upgrade/patch file.
34 * The following "functions" within the selected file will be processed:
37 * argument: table_name
38 * behavior: if the table_name does not exist, the block will be executed
41 * argument: table_name
42 * behavior: if the table_name does exist, the block will be executed
45 * arguments: table_name colname
46 * behavior: if the table and column exist, the block will be executed
49 * arguments: table_name colname
50 * behavior: if the table exists but the column does not, the block will be executed
53 * arguments: table_name colname value
54 * behavior: If the table table_name does not have a column colname with a data type equal to value, then the block will be executed
56 * #IfNotColumnTypeDefault
57 * arguments: table_name colname value value2
58 * behavior: If the table table_name does not have a column colname with a data type equal to value and a default equal to value2, then the block will be executed
61 * arguments: table_name colname value
62 * behavior: If the table table_name does not have a row where colname = value, the block will be executed.
65 * arguments: table_name colname value colname2 value2
66 * behavior: If the table table_name does not have a row where colname = value AND colname2 = value2, the block will be executed.
69 * arguments: table_name colname value colname2 value2 colname3 value3
70 * behavior: If the table table_name does not have a row where colname = value AND colname2 = value2 AND colname3 = value3, the block will be executed.
73 * arguments: table_name colname value colname2 value2 colname3 value3 colname4 value4
74 * behavior: If the table table_name does not have a row where colname = value AND colname2 = value2 AND colname3 = value3 AND colname4 = value4, the block will be executed.
77 * desc: This is a very specialized function to allow adding items to the list_options table to avoid both redundant option_id and title in each element.
78 * arguments: table_name colname value colname2 value2 colname3 value3
79 * behavior: The block will be executed if both statements below are true:
80 * 1) The table table_name does not have a row where colname = value AND colname2 = value2.
81 * 2) The table table_name does not have a row where colname = value AND colname3 = value3.
84 * arguments: table_name colname value
85 * behavior: If the table table_name does have a row where colname = value, the block will be executed.
88 * arguments: table_name colname value colname2 value2
89 * behavior: If the table table_name does have a row where colname = value AND colname2 = value2, the block will be executed.
92 * arguments: table_name colname value colname2 value2 colname3 value3
93 * behavior: If the table table_name does have a row where colname = value AND colname2 = value2 AND colname3 = value3, the block will be executed.
96 * desc: This function is most often used for dropping of indexes/keys.
97 * arguments: table_name colname
98 * behavior: If the table and index exist the relevant statements are executed, otherwise not.
101 * desc: This function will allow adding of indexes/keys.
102 * arguments: table_name colname
103 * behavior: If the index does not exist, it will be created
105 * #IfNotMigrateClickOptions
106 * Custom function for the importing of the Clickoptions settings (if exist) from the codebase into the database
108 * #IfNotListOccupation
109 * Custom function for creating Occupation List
112 * Custom function for creating Reaction List
115 * Custom function for importing new drug data
117 * #IfTextNullFixNeeded
118 * desc: convert all text fields without default null to have default null.
122 * desc: Execute SQL if the table has been created with given engine specified.
123 * arguments: table_name engine
124 * behavior: Use when engine conversion requires more than one ALTER TABLE
126 * #IfInnoDBMigrationNeeded
127 * desc: find all MyISAM tables and convert them to InnoDB.
129 * behavior: can take a long time.
131 * #IfDocumentNamingNeeded
132 * desc: populate name field with document names.
136 * all blocks are terminated with a #EndIf statement.
138 * @param string $filename Sql upgrade/patch filename
140 function upgradeFromSqlFile($filename, $path = '')
142 $sqlUpgradeService = new \OpenEMR\Services\Utils\
SQLUpgradeService();
143 $sqlUpgradeService->upgradeFromSqlFile($filename, $path);