_DB Migrate

When CT has been updated to a never version then there may also been an update in the Mysql database. You then have the option to migare the DB structure changes with the terminal commands bellow.

Can be used for DB creation and migration. Version stepping is being implemented.

Migrate using:

Control Tower: Migrate


Open the migration window under you profile image at the top right side. You need to have Super Admin permissions to have access.

You can either migrate a table in the database or just create a backup. If you choose to migrate then a backup will also automatically be created. If you check the checkbox "Läsa" then te migration will generate as SQL code but will not try to migrate.


Here you can load or remove backups

Terminal: Migrate

If you for some reason can not access the migrations within Control Tower then you also have the option to migrate with with ssh/terminal. You also have some more options here.


cd ct-admin/includes/


php migrate.php -h


php migrate.php -n MIGRATION -m ACTION -d DB_NAME -p PREFIX

-h: Help
-n string: Migration table class (pages, categories). Click here to se all »
-r int 0/1: Build and read SQL code. Will only read and will not execute migation. 
-b int 0/1: Create backup then migrate. After migration is complete it will return a bundle ID which you can use to load backup.
-l int Bundle ID: Will load backup.

Use only if you have a greater understanding:
-m string: Action (drop) // Standards is comming
-d string: Change DB name (Else default)
-p string: Change table prefix "ca_" (Else default)

Main usage

This is how you should mostly use the migration.

$ php migrate.php -n pages

Other Examples

This is how you should mostly use the migration.

1. $ php migrate.php -n MIGRATION -m METHOD (drop, down) -d DB_NAME -p PREFIX 
2. $ php migrate.php -n MIGRATION -r 1 // Read only, do not execute 
3. $ php migrate.php -n MIGRATION -b 1 // Create backup before migration 
4. $ php migrate.php -n MIGRATION -l BUNDLE // Load backup from BUNDLE number 

Supported migrations (-n)

This list will expand over time.

  • categories
  • media
  • media_set
  • menu
  • options
  • pages
  • plugins
  • templates
  • users
Plugin - migraton
  • plugins/archive
  • plugins/blog
  • plugins/free_services
  • plugins/news
  • plugins/objects
  • plugins/openings
  • plugins/productCases
  • plugins/projects
  • plugins/registrations
  • plugins/sales

PHP Examples: DB creation

You an also be create migrations or just manage the database with PHP


// Init class
// Arg1: Table name
$mig = new \query\create("test");

// Rename: IF table name is "test" or "test1" then it will be renamed to "test2".
// Has to be the first method to be called
//$mig->rename(["test1", "test2"]);

// Will create new stuff and alter current stuff

// Only create table

// Only alter table

// Only drop table

// Add/alter columns
$result = $mig->column("id", [
    "type" => "int",
    "length" => 11,
    "attr" => "unsigned",
    "index" => "primary",
    "ai" => true

])->column("testKey", [
    // Drop: Will drop the column
    "drop" => true,
    "type" => "int",
    "length" => 11,
    "index" => "index",
    "attr" => "unsigned",
    "default" => "0"

])->column("name", [
    "type" => "varchar",
    "length" => 200,
    "collate" => true,
    "default" => ""

])->column("loremname_1", [
    // Rename: IF old column name is "loremname_1 (se one row above)" or "loremname_2" then it will be renamed to "permalink"
    "rename" => ["loremname_2", "permalink"],
    "type" => "varchar",
    "index" => "index",
    "length" => 200,
    "collate" => true


// Will execute migration

// Get executed rows as SQL string that can be used manually 
// Can be called before execute has even been triggered

Complete function list

__construct(string $table, $prefix = false)