<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Migration 2 - insert basic system details, and create admin user and company
*/
final class Version20230908155244 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// INSERT INTO account_settings
$accountSettingsData = array(
array(1, 'Free Trail'),
array(2, 'Silver'),
array(3, 'Gold'),
array(4, 'Diamond'),
);
foreach($accountSettingsData as $d) {
$this->addSql('INSERT INTO account_settings (id,version) VALUES (?,?)', $d);
}
// INSERT INTO terminology
$terminologyData = array(
array(1, 'column', 'Column', 'Columns'),
array(2, 'row', 'Row', 'Rows'),
array(3, 'card', 'T-card', 'T-cards'),
array(4, 'board', 'Board', 'Boards'),
array(5, 'my_board', 'My board', 'My boards'),
array(6, 'user_type', 'User Type', 'User Type'),
array(7, 'user', 'User', 'Users'),
array(8, 'card_name', 'Card Name', 'Card Name'),
array(9, 'user_privilege', 'User Privilege', 'User Privileges')
);
foreach($terminologyData as $d) {
$this->addSql('INSERT INTO `terminology` (`id`, `terminology_key`, `singular_text`, `plural_text`) VALUES (?,?,?,?)', $d);
}
$companyId = 1;
$userId = 1;
$userTypeId = 1;
$now = (new \DateTime('now'))->format('Y-m-d H:i:s');
// INSERT INTO company
$companyData = array(
array($companyId, 'LTS', 1, 0, NULL, NULL, NULL, NULL, NULL, NULL),
);
foreach($companyData as $d) {
$this->addSql('INSERT INTO `company` (`id`, `company_title`, `is_active`, `is_deleted`, `created_at`, `created_by`, `updated_at`, `updated_by`,'
. ' `deleted_at`, `deleted_by`)'
. ' VALUES (?,?,?,?,?,?,?,?,?,?)', $d);
}
// INSERT INTO company_settings
$companySettingsData = array(
array(1, $companyId, 'en', 'C_M_D_Y', 'H_M_A', 'TH', 'C_M_D_Y_H_M_A', 'Asia/Calcutta', 10, 5, 5, 10, 10, 5, 15, 1, 1, 1, 1, 1, 1, 1, 1),
);
foreach($companySettingsData as $d) {
$this->addSql('INSERT INTO `company_settings` (`id`, `company_id`,`system_language`, `date_format`, `time_format`, `week_start_day`, `datetime_format`,'
. ' `timezone`, `no_of_users`, `no_of_user_types`, `no_of_boards`, `no_of_columns`, `no_of_rows`, `no_of_card_layouts`, `no_of_card_layout_fields`,'
. ' `has_excel_upload`, `has_multiple_layouts`, `has_multiple_section`, `has_card_timer`, `has_theme_customization`, `has_transfer_card`,'
. ' `has_draft_cards`, `has_skill_matrix`) '
. ' VALUES (?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?)', $d);
}
// INSERT INTO tc_user_type
$userTypeData = array(
array($userTypeId, $companyId, 'Administrator', '[\"ROLE_USER\", \"ROLE_ADMIN\"]', 1, 0, 0, $now),
);
foreach($userTypeData as $d) {
$this->addSql('INSERT INTO `tc_user_type` (`id`, `company_id`, `type_title`, `roles`, `is_active`, `is_default`, `is_deleted`, `created_at`) '
. ' VALUES (?,?,?,?,?, ?,?,?)', $d);
}
// INSERT INTO user
$userData = array(
array($userId, '[email protected]', '["ROLE_ADMIN"]', $userTypeId, '$2y$13$lkpQ20pF267MvLZp8Y8VI.5672BdyRT.ghQoM0gWpWiGj/w8pta2G', 0, 1, 1, 1),
);
foreach($userData as $d) {
$this->addSql('INSERT INTO `user` (`id`, `email`, `roles`, `user_type`, `password`, `main_admin`, `super_admin`, `is_verified`, `is_active`) '
. ' VALUES (?,?,?,?,?, ?,?,?,?)', $d);
}
// INSERT INTO user
$userProfileData = array(
array(1, $userId, 1, 'ADMIN', 'LTS'),
);
foreach($userProfileData as $d) {
$this->addSql('INSERT INTO `user_profile` (`id`, `user_id`, `ref_id`, `first_name`, `last_name`) '
. ' VALUES (?,?,?,?,?)', $d);
}
// INSERT INTO company_user
$companyUserData = array(
array(1, $companyId, $userId, 1, 1, $now),
);
foreach($companyUserData as $d) {
$this->addSql('INSERT INTO `company_user` (`id`, `company_id`, `user_id`, `is_main_user`, `is_default_company`, `assigned_date`) '
. ' VALUES (?,?,?,?,?,?)', $d);
}
}
public function down(Schema $schema): void
{
// DELETE FROM account_settings
$data = array(
array(1, 'Free Trail'),
array(2, 'Silver'),
array(3, 'Gold'),
array(4, 'Diamond'),
);
foreach($data as $d) {
$this->addSql('DELETE FROM `account_settings` WHERE `account_settings`.`id` = ?', array($d[0]));
}
// DELETE FROM terminology
$data = array(
array(1, 'column', 'Column', 'Columns'),
array(2, 'row', 'Row', 'Rows'),
array(3, 'card', 'T-card', 'T-cards'),
array(4, 'board', 'Board', 'Boards'),
array(5, 'my_board', 'My board', 'My boards'),
array(6, 'user_type', 'User Type', 'User Type'),
array(7, 'user', 'User', 'Users'),
array(8, 'card_name', 'Card Name', 'Card Name'),
array(9, 'user_privilege', 'User Privilege', 'User Privileges')
);
foreach($data as $d) {
$this->addSql('DELETE FROM `terminology` WHERE `terminology`.`id` = ?', array($d[0]));
}
$companyId = 1;
$userId = 1;
$userTypeId = 1;
$this->addSql('DELETE FROM `company` WHERE `company`.`id` = ?', array($companyId));
$this->addSql('DELETE FROM `company_settings` WHERE `company_settings`.`company_id` = ?', array($companyId));
$this->addSql('DELETE FROM `tc_user_type` WHERE `tc_user_type`.`id` = ?', array($userTypeId));
$this->addSql('DELETE FROM `user` WHERE `user`.`id` = ?', array($userId));
$this->addSql('DELETE FROM `user_profile` WHERE `user_profile`.`user_id` = ?', array($userId));
$this->addSql('DELETE FROM `company_user` WHERE `company_user`.`company_id` = ? AND `company_user`.`user_id` = ?', array($companyId, $userId));
}
}