-
Notifications
You must be signed in to change notification settings - Fork 26
Changing Schema
Yo-An Lin edited this page Apr 26, 2017
·
1 revision
Oh if you forgot to write some model columns, you may add them now:
...
$this->column('year')
->integer()
->label('Year')
;
$this->column('subtitle')
->varchar(260)
->label('Subtitle')
;
...Don't worry about it, just run maghead schema again, and it will show you the difference:
$ maghead schema
Found schema classes
Checking MyApp\Model\BookSchema...
Done
Comparing...
--- books:data source [default]
+++ books:src/MyApp/Model/Book.php
@@ columns @@
+ year integer isa:int, label:Year
+ subtitle varchar(260) isa:str, label:Subtitle
You don't need to write the alter table syntax by hands, Maghead provides a simple command tool to help you migrate the database schema:
$ maghead migrate automatic
Loading schema objects...
QueryOK: ALTER TABLE books ADD COLUMN year integer
QueryOK: ALTER TABLE books ADD COLUMN subtitle varchar(260)
The above command compares your database schema and your model schema, the migration manager generates the difference output, base on the difference, it generates the alter table SQL statements for you.