DO NOT create or modify database thru tools like PHPMyadmin. Use code instead.
Best practice in Yee is not to manually create your database, but to use code to do it. This allows collaboration in large team possible where everybody may have their own version of local database in development environment.
Migration also is a key player in modular architecture, where module can be install and upgrade easily by super admin. In this case, migration code either sit in insallDb function at module like SampleModule.phpor; sit in the upgrades folder.
Create Table
Table column naming is use to instruct Yee on how to generate code for models, controllers and views. Hence, naming convention for table columns is strict and must be follow by all developers. Check for more detail.
$migration->createTable('sample', array(
'id' => 'pk',
'code' => 'string NOT NULL',
'sample_group_id' => 'integer NULL',
'sample_zone_code' => 'string NULL',
'title_en' => 'string NOT NULL',
'title_ms' => 'string NOT NULL',
'title_zh' => 'string NOT NULL',
'text_short_description_en' => 'string NOT NULL',
'text_short_description_ms' => 'string NOT NULL',
'text_short_description_zh' => 'string NOT NULL',
'html_content_en' => 'longtext NULL',
'html_content_ms' => 'longtext NULL',
'html_content_zh' => 'longtext NULL',
'image_main' => 'string NULL',
'file_backup' => 'string NULL',
'price_main' => 'decimal(10,0) NULL DEFAULT 0',
'gender' => 'string NULL',
'age' => 'integer NULL',
'csv_keyword' => 'mediumtext NULL',
'ordering' => 'double NOT NULL DEFAULT 1',
'date_posted' => 'integer NOT NULL',
'is_active' => 'boolean NOT NULL DEFAULT 1',
'is_public' => 'boolean NOT NULL DEFAULT 1',
'is_member' => 'boolean NOT NULL DEFAULT 1',
'is_admin' => 'boolean NOT NULL DEFAULT 1',
'date_added' => 'integer NOT NULL',
'date_modified' => 'integer NOT NULL',
));
$migration->createIndex('code', 'sample', 'code', true); // a unique index
$migration->createIndex('sample_group_id', 'sample', 'sample_group_id', false); // a not unique index
and the combination (combine more than 1 table fields as an unique index, mostly appear in many-to-many table):
This is handy when you need to bulk update your existing data in database.
$sql = 'UPDATE `eventbrite_organization_webhook` as t LEFT JOIN `organization` as f ON t.organization_code=f.code SET t.organization_id=f.id';
Yii::app()->db->createCommand($sql)->execute();
Create Meta
MetaStructure::initMeta('organization', 'community', 'urlYoutubeCoverVideo', 'string', 'Cover Youtube Video URL', 'URL to display youtube video in community organization page', '');
Create Setting
Setting::setSetting('sample-var1', 'Hello World 0.2', 'string');