I have a SQL code from yii demo blog:
CREATE TABLE tbl_post
(
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(128) NOT NULL,
content TEXT NOT NULL,
tags TEXT,
status INTEGER NOT NULL,
create_time INTEGER,
update_time INTEGER,
author_id INTEGER NOT NULL,
CONSTRAINT FK_post_author FOREIGN KEY (author_id)
REFERENCES tbl_user (id) ON DELETE CASCADE ON UPDATE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
INSERT INTO tbl_lookup (name, type, code, position) VALUES ('Draft', 'PostStatus', 1, 1);
I need to write it to a file migration in a function up(), how to write the code? And where can I read about the addition of tables in the migration file (I mean how to write, for example "varchar" or "string")? Is it possible to add a file migration "INSERT", "UPDATE"?
In your function up() or safeUp() you would add the following code:
There is an update() method available as well (insert has been shown above): http://www.yiiframework.com/doc/api/1.1/CDbMigration#update-detail