Leafiny Documentation
Setup
The module setup allows you to manage tables in the database.
Add SQL queries
In any module, create a setup directory. Add a SQL file with the sequence number : {sequence}.upgrade.sql (e.g. 100.upgrade.sql
).
The sequence number is the order in which the files will be executed. If you need to add a column to the cms_page table, add a file with a sequence number greater than the SQL file that created the table.
We want to create a new table:
# modules/Frontend/setup/100.upgrade.sql
CREATE TABLE IF NOT EXISTS `document` (
`document_id` INT(11) unsigned NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`content` TEXT NULL,
`language` VARCHAR(5) NOT NULL DEFAULT 'en_US',
`status` INT(1) NOT NULL DEFAULT 0,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`document_id`)
) ENGINE=InnoDB;
Run setup
A lock file is located in the var/lock directory : setup.lock
. When the lock file is deleted, Leafiny:
- retrieves all SQL setup files and sorts them by sequence number
- check in the core_setup table if the queries have already been executed
- execute new queries and add the SQL file name in the core_setup table
- create the setup.lock file in the var/lock directory
To run new queries from module's SQL file, remove the lock file and refresh a page.