Welcome Guest, Not a member yet? Register   Sign In
Database Migration
#1

Hi,

I hope someone can help?

I've spent an awful lot of time trying to  Database Migrations working, I've followed the user manual closely and eventually got a prototype working with latest() method.

It is my intention to not only use Migration to manage changes to the DB going forward but also to onboard new customers with a their own set of tables with a combination of Migration and Seed.

I believe I would need to use the force() method to create customers with a their own set of tables, and the latest() method to implement changes across the entire DB?

However, I do not know if this is the right approach? And, and if it is, I cannot fathom how to call a specific migration file using the force method. Can force() process a migration not stored in App\DatabaseMigrations\  ???

My controller (below) will not find the file using force() whether the file is named "create_new_tables" like below, or "2022-01-21-223112_create_new_tables"

PHP Code:
namespace App\Controllers;

class 
Migrate extends \CodeIgniter\Controller
{
    public function index()
    
       $migrate = \Config\Services::migrations();
       $data['lang'] = 'Companies';
       $data['page_name'] = lang($data['lang'].'.title');
       $data['action'] = 'newco';
 
       if($this->request->getServer('REQUEST_METHOD') == 'POST' && $this->request->getPost('db_conn') && $this->request->getPost('db_prefix')){
 
          helper(['form''url']);
 
         if ($this->request->getPost('db_conn')) { 
             $data['db_conn'] = $this->request->getPost('db_conn'FILTER_SANITIZE_STRING);
         
 
         if ($this->request->getPost('db_prefix')) { 
             $data['db_prefix'] = $this->request->getPost('db_prefix'FILTER_SANITIZE_STRING);
         }
 
         $sessUpdate = [
          'dbprefixtemp' => $data['db_prefix'],
          'dbconntemp' => $data['db_conn']
         ];

         session()->set($sessUpdate);

         try {
           $migrate->force('App\Database\Migrations\create_new_tables');
           return redirect()->back()->withInput()->with('success'lang($data['lang'].'.success'));
         } catch (\Throwable $e) {
           return redirect()->back()->withInput()->with('error'lang($data['lang'].'.notadded')); 
         }
       }
 
       echo view('includes/headers/page_header'$data);
       echo view('companies/new_company_form'$data);
       echo view('includes/footers/copyright'$data);
       echo view('includes/js/coreJS');
       echo view('includes/footers/page_end_tags');
    }

Reply


Messages In This Thread
Database Migration - by 68thorby68 - 01-21-2022, 02:20 PM
RE: Database Migration - by BilltheCat - 01-22-2022, 01:42 AM
RE: Database Migration - by InsiteFX - 01-22-2022, 02:48 AM
RE: Database Migration - by 68thorby68 - 01-22-2022, 04:08 AM
RE: Database Migration - by 68thorby68 - 01-22-2022, 07:29 AM
RE: Database Migration - by iRedds - 01-22-2022, 09:33 AM
RE: Database Migration - by 68thorby68 - 01-27-2022, 03:56 AM
RE: Database Migration - by kenjis - 01-22-2022, 07:59 PM
RE: Database Migration - by kenjis - 01-27-2022, 04:16 AM
RE: Database Migration - by 68thorby68 - 01-27-2022, 04:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB