You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- `database_source` is the source database configuration
61
-
- `database_target`is the target database configuration
60
+
- `databaseSource` is the source database configuration
61
+
- `databaseTarget`is the target database configuration
62
62
- `table`is an array containing all the tables to be imported. Tables not listed in `table` will not be imported.
63
-
- `maximum_record`is the maximum number of records in a single insert query. Note that MagicObject does not care about the size of the data in bytes. If you need to adjust the maximum records per table, specify `maximum_record` on the table you want to set.
63
+
- `maximumRecord`is the maximum number of records in a single insert query. Note that MagicObject does not care about the size of the data in bytes. If you need to adjust the maximum records per table, specify `maximumRecord` on the table you want to set.
64
64
65
65
1. `source` (required)
66
66
@@ -70,7 +70,7 @@ Table name of the source database
70
70
71
71
Table name of the target database
72
72
73
-
3. `maximum_record` (optional)
73
+
3. `maximumRecord` (optional)
74
74
75
75
`maximum records`on a table is used to reset the number of records per `insert` query on a table for that table. This setting will override the global setting.
76
76
@@ -80,13 +80,14 @@ Table name of the target database
80
80
81
81
`map`is an array of text separated by colons. On the left side of the colon are the column names in the target table and database while on the right side of the colon are the column names in the source table and database.
82
82
83
-
5. `pre_import_script` (optional)
83
+
5. `preImportScript` (optional)
84
84
85
-
`pre_import_script`is an array of queries that will be executed before the data import begins. `pre_import_script` is usually used to clear data from a table and reset all sequence or auto increment values from the target table.
85
+
`preImportScript`is an array of queries that will be executed before the data import begins. `preImportScript` is usually used to clear data from a table and reset all sequence or auto increment values from the target table.
86
86
87
-
6. `post_import_script` (optional)
87
+
6. `postImportScript` (optional)
88
+
89
+
`postImportScript`is an array of queries that will be executed after the data import is complete. `postImportScript` can be used for various purposes such as fixing some data on the target table including taking values from other tables. Therefore post_script must be run after all tables have been successfully imported.
88
90
89
-
`post_import_script`is an array of queries that will be executed after the data import is complete. `post_import_script` can be used for various purposes such as fixing some data on the target table including taking values from other tables. Therefore post_script must be run after all tables have been successfully imported.
$sql = (new PicoDatabaseUtilMySql())->importData($config, function($sql, $source, $target){
109
+
$sql = (new PicoDatabaseUtilMySql())->importData($config, function($sql, $tableNameSource, $tableNameTarget, $databaseSource, $databaseTarget){
109
110
$fp = fopen(__DIR__.'/db.sql', 'a');
110
111
fwrite($fp, $sql.";\r\n\r\n");
111
112
fclose($fp);
@@ -118,9 +119,13 @@ $sql = (new PicoDatabaseUtilMySql())->importData($config, function($sql, $source
118
119
php import.php
119
120
```
120
121
121
-
MagicObject will create a database query that is saved into a file named `db.sql`. The data is taken from the `database_source` but the table and column names have been adjusted to the `database_target`. This query can be run in the `database_target`. If you want to empty a table before importing data, you can add a pre_import_script to each table. Keep in mind that all pre_import_scripts will be executed before MagicObject starts importing data.
122
+
MagicObject will generate SQL queries based on the configuration in `import.yml`. These queries are written into `db.sql`. The data is read from the `databaseSource`, while table and column names are automatically mapped to the `databaseTarget`. The resulting `db.sql` file can then be executed on the `databaseTarget`.
123
+
124
+
If you want to clear a table before importing data, you can define a `preImportScript` for that table. All preImportScripts will be executed before MagicObject starts the data import process.
125
+
126
+
For more complex databases, you can use the method `PicoDatabaseUtilMySql::autoConfigureImportData()` to generate a configuration template. This method compares the source and target databases and automatically maps tables and columns. If a table exists in the target but not in the source, MagicObject will mark its source as `???`. Likewise, if a column exists in the target table but not in the source, its source will be marked as `???`. You can then manually adjust these placeholders in the configuration file.
122
127
123
-
If the database is too complex, users can use the PicoDatabaseUtilMySql::autoConfigureImportData() method to create a configuration template to avoid missing table and column names. Users simply specify the source database and the target database. MagicObject will check the tables and columns in both databases. If a table exists in the target database but not in the source database, MagicObject will write ??? as its source name. Users can manually change the name of this table. In the same table, if a column exists in the target database but not in the source database, MagicObject will write ??? as its source name. Users can manually change the name of this column.
128
+
In addition to generating an SQL file, users can also choose to **execute the generated queries directly on the target database**. This allows the import process to be performed automatically without the need to run the resulting `db.sql` file manually.
124
129
125
130
Here is an example of how to create a database import configuration template.
126
131
@@ -129,7 +134,7 @@ Here is an example of how to create a database import configuration template.
0 commit comments