定义 SubSonic 3 ActiveRecord 迁移
我正在使用 SubSonic 3 ActiveRecord 启动 ASP.NET MVC 项目。 我添加了一个具有主键ID的表Users,并重新编译了T4文件以生成User类。
我想确保,随着开发的进行,我可以随时重新生成/迁移数据库。 看来我必须在数据库中创建表和关系,重新生成 ActiveRecord 类并按照 http: 中所述进行迁移: //subsonicproject.com/docs/3.0_Migrations。 定义迁移的旧 2.x 方式似乎不再可用。
有没有一种方法可以通过更改模型类来从代码而不是数据库驱动开发,并相应地迁移数据库,而不使用 SimpleRepository? 我不想将生成的代码放入源代码存储库,但如果不这样做,我就会丢失数据库架构(除非我手动导出并保存它)。
I'm starting an ASP.NET MVC project using SubSonic 3 ActiveRecord. I added a table Users with a primary key ID and recompiled T4 files to generate User class.
I want to make sure that, as I go along with the development, I can regenerate/migrate the database at any point. It looks like I have to create tables and relationships in the database, regenerating ActiveRecord classes and doing migration as described in http://subsonicproject.com/docs/3.0_Migrations. The old 2.x way of defining migrations doesn't seem to be available any more.
Is there a way to drive development from the code rather than database, by changing model classes, and have the database migrated accordingly, without using SimpleRepository? I don't want to put generated code into source code repository, but if I don't, I lose database schema (unless I export and save it manually).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您仍然可以使用 SubSonic 3 作为 DAL,并让 SubSonic 2.2 为您生成迁移。
您只需要 sonic.exe 及其依赖项来执行迁移文件。
更准确地说,我的 DataLayer 项目中有文件夹 Migrations,它保留所有迁移文件,但将 BuildAction 设置为无。 所以我有语法突出显示(但没有错误检查,除非我将 BuildAction 设置回编译),但代码不会弄乱我的项目。
当然,您可以将它们保留在自己的项目中。 但我喜欢这种方式,将其置于版本控制之下,并确保我当前的 DAL 与我的迁移版本相匹配。
此外,我已将配置文件命名为“migration.config”(而不是“app.config/web.config”)并使用此命令行来执行迁移。
请注意 /config 开关覆盖 sonic.exe 正在查找的配置文件。
You can still use SubSonic 3 as a DAL and let SubSonic 2.2 generate the migrations for you.
You just need sonic.exe and it's dependencies to execute the migration files.
To be more precise, I have folder Migrations in my DataLayer Project, that keeps all the migration Files but set the BuildAction to none. So I have Syntax Highlighting (but no error checking unless I set BuildAction back to compile) but the code does not mess my project.
You can keep them in an own project, of course. But I like it this way to have it under version control and be sure that my current DAL is matching my migration version.
In addition, I have named my config file migration.config (instead of app.config/web.config) and use this commandline to execute my migrations.
Notice the /config switch to override the config file sonic.exe is looking for.
您可以查看 SimpleRepository:
http://subsonicproject.com/docs/Simple_Repo_5_Minute_Demo
You could have a look at SimpleRepository:
http://subsonicproject.com/docs/Simple_Repo_5_Minute_Demo
您链接到的文档确实指出:
“底线:如果您是一名关心数据库设计的开发人员,迁移可能不适合您”
我怀疑对于您想要的设计细节(我也会),迁移可能不合适?
The document you linked to does state:
"Bottom line: if you're a developer that is concerned about database design, migrations might not be for you"
I suspect that for the detail of design you want (and I would too), the migrations may not be suitable?