[LRUG] Rails schema line order changing

Edmond Lepedus ed.lepedus at googlemail.com
Mon Mar 1 02:25:33 PST 2021


Not a Rails answer, as I’m in the TypeScript world at the moment, but the principles may apply:

For the last 6 months or so, we’ve taken to dropping the entire schema and re-running all migrations on startup & hot-reload. This is very common for test envs, but actually works surprisingly well in development to, for the same reasons it’s recommended for tests. The only two caveats we’ve found so far:

1. It doesn’t prevent developers from modifying past migrations, meaning everything will work as expected in dev/test, but the migration won’t be applied in staging/prod
2. It can start slowing down if you have large amounts of seed data. One of our systems requires 10k rows to be present in a given table, and it can take 1-5s each time it gets seeded. 

> On 1 Mar 2021, at 09:47, Ed James <ed.james.spam at gmail.com> wrote:
> 
> Some surprising behaviour to be aware of when using “db:schema:load” which has caught us out a few times before…
> 
> Create a new branch, add a migration on your branch and run the migration. Commit the change.
> Go back to your “master” branch.
> Run “rake db:schema:load”
> You’d think at this point that the migration on your feature branch would’ve been “reset”, but…
> Check out your feature branch again and try to apply your migration. Nothing will happen.
> 
> When you run “db:schema:load” it doesn’t touch the data in your “schema_migrations” table but it obviously does touch your db schema! So in the example above, the migration version will still be present in your “schema_migrations” table but the actual change will not have been applied to your db => busted db and much pain and suffering.
> 
> Hopefully this helps someone :) 
> 
> 
>        	Ed James 
> I will respect your spam <mailto:ed.james.spam at gmail.com>
> 
>> On 1 Mar 2021, at 08:18, Patrick Gleeson <patrick.c.gleeson at gmail.com <mailto:patrick.c.gleeson at gmail.com>> wrote:
>> 
>> Step one: Whoever yells loudest gets to keep their database
>> Step two: Everyone else does rails db:reset on their development databases, and possibly just db:schema:load on their test ones if you have seed data you don't want in your test db.
>> 
>> The key is that db:schema:load reads from the schema file as-is, rather than reading from the migrations and re-constructing the schema from the database.
>> 
>>  - Patrick
>> 
>> Why aren't you coding? <https://whyarentyoucoding.com/>
>> On Mon, 1 Mar 2021 at 08:10, Stuart Harrison <pezholio at gmail.com <mailto:pezholio at gmail.com>> wrote:
>> Morning LRUG
>> 
>> I wanted to share an annoyance I've had on multiple projects, and wondered if anyone had any fixes for it? 
>> 
>> If there are multiple devs on a project committing a bunch of migrations and running `db:migrate`, it seems that, over time, the order of columns in the schema.rb file jumps around every time the command is run. 
>> 
>> I can get around this by only committing the relevant line(s) when I run a migration, but this does get annoying. 
>> 
>> I'm sure there is a solution, but it's disappeared out of my head, and seems to be an ungoogleable problem, so was wondering if anyone had come across a solution?
>> 
>> Cheers
>> 
>> Stu
>> _______________________________________________
>> Chat mailing list
>> Chat at lists.lrug.org <mailto:Chat at lists.lrug.org>
>> Archives: http://lists.lrug.org/pipermail/chat-lrug.org <http://lists.lrug.org/pipermail/chat-lrug.org>
>> Manage your subscription: http://lists.lrug.org/options.cgi/chat-lrug.org <http://lists.lrug.org/options.cgi/chat-lrug.org>
>> List info: http://lists.lrug.org/listinfo.cgi/chat-lrug.org <http://lists.lrug.org/listinfo.cgi/chat-lrug.org>
>> _______________________________________________
>> Chat mailing list
>> Chat at lists.lrug.org <mailto:Chat at lists.lrug.org>
>> Archives: http://lists.lrug.org/pipermail/chat-lrug.org
>> Manage your subscription: http://lists.lrug.org/options.cgi/chat-lrug.org
>> List info: http://lists.lrug.org/listinfo.cgi/chat-lrug.org
> 
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> Archives: http://lists.lrug.org/pipermail/chat-lrug.org
> Manage your subscription: http://lists.lrug.org/options.cgi/chat-lrug.org
> List info: http://lists.lrug.org/listinfo.cgi/chat-lrug.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20210301/7c7c8149/attachment.html>


More information about the Chat mailing list