Add web-based database migration script for line_label field
This commit is contained in:
parent
79fdc0d8ca
commit
8277217cc7
78
migrate_line_label_field.php
Normal file
78
migrate_line_label_field.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* Database Migration Script for DeclarationTVA Module
|
||||
*
|
||||
* This script migrates the line_label field from varchar(255) to TEXT
|
||||
* to handle long account label combinations with many mapped accounts.
|
||||
*
|
||||
* Run this script through your web browser to apply the migration.
|
||||
*/
|
||||
|
||||
// Include Dolibarr main file
|
||||
require_once '../../main.inc.php';
|
||||
|
||||
// Check if user has admin rights
|
||||
if (!$user->admin) {
|
||||
die("Access denied. Admin rights required.");
|
||||
}
|
||||
|
||||
// Set page title
|
||||
$title = "DeclarationTVA - Database Migration";
|
||||
$mainmenu = "home";
|
||||
$leftmenu = "home";
|
||||
|
||||
// Include Dolibarr header
|
||||
llxHeader($title, $mainmenu, $leftmenu);
|
||||
|
||||
print '<div class="fichecenter">';
|
||||
print '<div class="fichehalfleft">';
|
||||
print '<div class="titre">DeclarationTVA Database Migration</div>';
|
||||
|
||||
// Check if migration has already been applied
|
||||
$sql_check = "SHOW COLUMNS FROM " . MAIN_DB_PREFIX . "declarationtva_ca3_lines LIKE 'line_label'";
|
||||
$result_check = $db->query($sql_check);
|
||||
|
||||
if ($result_check) {
|
||||
$obj_check = $db->fetch_object($result_check);
|
||||
if ($obj_check && strpos($obj_check->Type, 'text') !== false) {
|
||||
print '<div class="info">';
|
||||
print '<strong>Migration already applied!</strong><br>';
|
||||
print 'The line_label field is already TEXT type. No migration needed.';
|
||||
print '</div>';
|
||||
} else {
|
||||
// Apply the migration
|
||||
print '<div class="info">';
|
||||
print '<strong>Applying migration...</strong><br>';
|
||||
|
||||
$sql_migration = "ALTER TABLE `" . MAIN_DB_PREFIX . "declarationtva_ca3_lines`
|
||||
MODIFY COLUMN `line_label` TEXT DEFAULT NULL
|
||||
COMMENT 'Combined account labels for this CA-3 line (can be long with many accounts)'";
|
||||
|
||||
$result_migration = $db->query($sql_migration);
|
||||
|
||||
if ($result_migration) {
|
||||
print '<div class="ok">';
|
||||
print '<strong>Migration successful!</strong><br>';
|
||||
print 'The line_label field has been changed from varchar(255) to TEXT.<br>';
|
||||
print 'You can now recalculate your declarations to see the full account labels.';
|
||||
print '</div>';
|
||||
} else {
|
||||
print '<div class="error">';
|
||||
print '<strong>Migration failed!</strong><br>';
|
||||
print 'Error: ' . $db->lasterror();
|
||||
print '</div>';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print '<div class="error">';
|
||||
print '<strong>Error checking current field type!</strong><br>';
|
||||
print 'Error: ' . $db->lasterror();
|
||||
print '</div>';
|
||||
}
|
||||
|
||||
print '</div>';
|
||||
print '</div>';
|
||||
|
||||
// Include Dolibarr footer
|
||||
llxFooter();
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user