Improve migrations support
#1
Posted 30 June 2012 - 09:38 AM
Or ... can migrations auto-learn schema differences?
#2
Posted 30 June 2012 - 09:52 AM
Btw: I think we had that discussion already. Can't find the thread right now ...
#3
Posted 30 June 2012 - 10:30 AM
public function types () {
return array(
'id' => array(
'type' => 'pk',
),
'name' => array(
'type' => 'varchar',
'size' => '255',
'nullable' => 'true',
),
'address' => array(
'type' => 'relation',
'relation_type' => 'belongs_to',
'model' => '{{relations}}',
)
);
}
Or something like that.
#4
Posted 30 June 2012 - 10:33 AM
#5
Posted 30 June 2012 - 02:17 PM
sensorario, on 30 June 2012 - 09:38 AM, said:
Or ... can migrations auto-learn schema differences?
I would prefer if it would be the other way around as I always start with migrations first, and then modify the model(s).
It would be nice if the migration could adjust the involved models without my intervention..
'Nice' as in not really needed.
#6
Posted 01 July 2012 - 07:00 AM
If I'll can only start with migrations, yii's migrations are not scalable. jacmoe, I really need this stuff.
#8
Posted 02 July 2012 - 12:32 PM
Fork on github
Follow phundament on Twitter
DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
#9
Posted 02 July 2012 - 04:24 PM
sensorario, on 01 July 2012 - 07:00 AM, said:
total nonsense, happily using migrations in a distributed team of around 20 devs and it's really not a problem. In fact it's generally quite important to be specific about exactly the kind of fields you're creating, because otherwise you'll end up with performance problems. E.g. how do you automatically add an index? Creating migrations automagically will not solve the one pain point when working with distributed teams, which is when migrations from different developers clash, but this is really just a communications issue (merge more often!)
In fact if you're syncing the db to the model, you don't need migrations at all, some frameworks do this, but it's not a good approach in my opinion, too much black magic.
#10
Posted 03 July 2012 - 08:02 AM
The database schema is generated by the migrations. And can't be source controlled.
It's just output. Generated.
I don't see the problem.
As Phpnode said, migrations is well suited in a distributed team.
I would like, however, more control about the fields generated by migrations, like the size of the text fields, to improve performance.
Migrations works great for agile development because it encourages iterative development, and that includes the schema.
Before Yii had that, it was a pain in the arse.
#11
Posted 03 July 2012 - 08:36 AM
jacmoe, on 03 July 2012 - 08:02 AM, said:
That's already possible. You can specify "VARCHAR(70) NOT NULL" as field type. Obviously your migrations will no longer be db-agnostic, but it works
#12
Posted 03 July 2012 - 10:39 AM
#13
Posted 03 July 2012 - 11:49 PM
phpnode, on 02 July 2012 - 04:24 PM, said:
Well, work a project developed with a big team (with another framework). We have a phing task called daily. Every day we start our job we run "phing daily". This task update our database. We do not care to know if someone update database. I just run a command every day that keeps the line db. But .. I think this is also possible with yii. The issue is another one.
phpnode, on 02 July 2012 - 04:24 PM, said:
In yii we create first the table, and then model. Good or not, we are not able to do the inverse (from model to db) just because our model is not translatable in a table. Doctrine2 is able to create a two-way relationship between classes and php database. Is not black magic. But imho Doctrine2 is too verbose.
If i could define mi model:
public function types () {
return array(
'id' => array(
'type' => 'pk',
),
'name' => array(
'type' => 'string',
'size' => '777',
'nullable' => 'true',
),
);
}I can traslate model to db and db to model. I think is great!!! I can auto-generate migrations.
A client of mine has started a job without migrations. He has a lot of tables. I need to create schema with migration now. But I cant.
Maybe with DumpSchemaCommand I'll can. Thank you @schmunk
#14
Posted 04 July 2012 - 06:55 AM
You can do the above with migrations.
Perhaps you want to do this directly in the model instead of in a migration?
#15
Posted 04 July 2012 - 06:58 AM
What's stopping you?
It would be handy to let Yii use the model(s), but what about when you add/change/remove fields?
How do you deal with that?
That's where migrations shine.
#16
Posted 04 July 2012 - 10:39 AM
The following issues are created by using models as migrations:
- No way can migrations be removed so we now have two things doing the same thing (essentially).
- Which to run first, models or migration? a migration might need a model change to be made before it can run or vice versa, adds confusion and potential bugs.
- you wouldn't be able to rollback model changes.
- when running yiic migrate would you also check models? have to check all models for changes against tables, time and resource intensive (my current project has 50 models).
- if you make a separate yiic command for model migrations you add confusion of extra commands.
While there might be solutions for the above, I'm going to quote "if it ain't broke...".

Quote
#17
Posted 04 July 2012 - 03:20 PM
If you're dealing with modules as extension packages, you don't always want to tie these migrations into your application migrations.
Fork on github
Follow phundament on Twitter
DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
#18
Posted 05 July 2012 - 11:24 AM
#19
Posted 08 July 2012 - 02:20 PM
samdark, on 05 July 2012 - 11:24 AM, said:
Yeah, I know, I am also using it, but I guess it needs some work to get it run smoothly with the package manager.
By the way, it's a bit off-topic, but I just noticed that your Yeeki module is only available as a whole Yii application, would be really nice to have a submodule here: https://github.com/s...pp/modules/wiki to include it into other projects - because I was looking for Yii wiki module
Just my two cents here, because I think migrations, packages, modules, configurations, themes and so on are very closely related to each other.
Fork on github
Follow phundament on Twitter
DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
#20
Posted 08 July 2012 - 02:26 PM
I think it's great that modules/extensions/packages/whatever can have their own migrations..
However, it would be much more useful if migrations could happen recursively.
The modules/extensions/packages/whatever could register with the MigrationManager so that it knows what to apply when the migrate command is run.
Chained migrations?
With dependencies checking?
Whatever it is, it would then be possible to just run yiic migrate and it will happen.

Help

This topic is locked














