如何一劳永逸地进行正确的迁移
我对我的用户表进行了一些迁移,它已经变得一团糟,我自己并没有真正遵循:)
理想情况下,我想做的是使用 Devise 库进行身份验证,并通过它创建我的用户表。
我应该删除表用户,并将累积的迁移文件合并为一个,然后运行 rake db:migrate 吗?或者有更好的方法吗?这样做的良好实践方法是什么?
另外,我想在新的迁移中添加 3 列,将firstName、lastName、company 字段添加到用户表中。我应该在哪里添加它以便创建这些字段?
谢谢, 亚历克斯
I have a few migrations for my users table and it has become a mess that I don't really follow myself :)
Ideally, what I want to do is use the Devise library for auth, and create my users table through that.
Should I do a drop table users, and merge my accumulated migrate files into one, and then run rake db:migrate ? Or is there a better way to do it? What is the good practice way of doing this?
Also, I'd like to add 3 more columns to the new migration for fistName,lastName,company fields to the users table. Where should I add that so those fields get created?
Thanks,
Alex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您单独进行开发时,您可以按照您想要的方式更改迁移文件(我仍然不相信它有那么有用,请参阅上面的评论)。
好吧,一旦您根据需要编辑了所有内容:
删除当前数据库:
rake db:drop
重新创建它:
rake db:create
迁移:
rake db:migrate
迁移过程在数据库本身中进行跟踪:
创建一个表并将其命名为
schema_migrations
,每个条目都是已完成的迁移,时间戳为一个 ID。因为您转储了数据库,所以不再有跟踪,您可以重新迁移。
When you're in dev, and alone, you can change your migration files the way you want (I'm still not convinced it's that useful, see my comment above).
Well, once you've edited everything as you want:
delete your current database:
rake db:drop
recreate it:
rake db:create
migrate:
rake db:migrate
The process of migrations is traced in the database itself:
one table is created and named
schema_migrations
, each entry is an already made migration with the timestamp as an id.Because you dump the db, there is no more trace and you can remigrate.