My first time with Padrino and DataMapper. If I understood correctly,
padrino g model Foo will make models/foo.rb as well as db/migrate/001_create_foos.rb.
In order to create an index, I need to specify it in the model, not in the migration.
padrino rake dm:auto:{upgrade|migrate} will generate the database from models, without paying attention to db/migrate folder.
So, it seems that migrations are only kept as "just in case" for upgrading production databases. Is there a way to generate a migration from the model? If not, does everyone else also have a headache trying to keep migrations up-to-date as you change your model? How do people write their migrations?
According Padrino documentation i guess you're right. The Orm section
states that the auto namespace won't use the generated migrations.
Basically, instead of writing migrations you can directly edit your schema.rb and perform a non destructive migration with padrino rake ar:auto:upgrade
I guess you can track the database with migrations removing the auto namespace as:
rake dm:migrate # Migrates the database to the latest version
rake dm:migrate:down[version] # Migrates down using migrations
rake dm:migrate:up[version] # Migrates up using migrations
And generate migrations as described in the Migration Generator section
Related
I'm confused on after we do db:migrate, what does the schema means? Does it automatically change the models if they are connected or do we need to manually change the models to reflect the schema?
If you're talking about db/schema.rb file, it is not the same thing as a migration. The migration is designed to run database commands to update the actual underlying database schema. When you run rake db:migrate it attempts to run any pending migrations on the database. If successful, it will also under the hood run rake db:schema:dump which will update the db/schema.rb file which reflects the latest version of the actual schema. If for some reason the migration fails because of some error, it will rollback and leave the schema in its previous state to having run the migration.
The models in a Rails don't touch the schema itself, but there are generators the help you create a migration file. For a better understanding of how all this works, you really should read through the documentation here
the db/schema.rb file represents the current configuration of the database, after any successful (or unsuccessful) migrations.
ActiveRecord uses db/schema.rb to 'automatically' configure attribute methods, for example if there's a users table with a column first_name then the User model will have a method name and a method name= as the getter and setter methods for that column.
You don't have to configure the models yourself, ActiveRecord does it all for you.
ActiveRecord also takes care of typecasting the variables as appropriate for the column defined in db/schema.rb.
We are looking to implement Continuous Integration using Circle CI but we are not sure on how should we proceed with our test database. We have the following alternatives in mind:
Run the migrations from scratch (the problem is that we have a lot of migration files, our first migrations were moving everything from MySQL and PostgreSQL and using a legacy database, so, it's rather complex).
Recreate the current DB and have a .sql file that will create our current tables, and then, we create a seeder to fill the information that we need.
But we are not sure which is the best alternative or if we're missing something?
Thank you
Is there a concise way to test Laravel migrations? I want establish the database up to the point of my new migration (including seeds etc) and then run my new migration and check the tests I have written for my seed data. The main issue is that I need to create my factory objects before the new migration is run, but after the other migrations run (creating all the original tables etc). As far as I know the only way to do it is either run every migration individually with the --path option, create the factory objects and finally run my new migration. Is there a better way?
I maintain a new but popular open source project based on Laravel 5.4. After a few months, we already have 100+ migrations in the database folder.
In a year from now, we'll easily have more than 1000 migrations with the current rate of features.
Rails has the same concept of migrations, but when migrations are run, they are ran against schema.rb, which is updated after the migrations have been run. This is super nice because for new installations, they don't have to run all those migrations. Only one is necessary.
Is there a way in Laravel to do the same? Reduce the number of migrations after a given period of time, or between major version, have a base schema with only few migrations? Thanks!
I have been learning about databases and wanted to know, if is there a Datamapper method -or another "ruby" way?- for creating an empty database rather than using create database "bd_name"; in psql, in a Sinatra project?
What you should be doing is creating a Rakefile and defining a Rake task to create the database and also a task to run the migrations after you make any structural changes to your database.
With DataMapper, this is somewhat more work than with ActiveRecord (which provides it's own DB tasks).
Have a look at the Rakefile provided by the Padrino framework for inspiration.