简体   繁体   English

使用Ruby on Rails创建新数据库

[英]Create a New Database with Ruby on Rails

Is there a way to create a new database in an ROR app automatically. 有没有一种方法可以在ROR应用中自动创建新数据库。

What I'm trying to do is create a new database for each new user that signs up for my site. 我正在尝试为注册我的网站的每个新用户创建一个新数据库。 so if the new user sign-up is successful a new database with some empty tables will be created. 因此,如果新用户注册成功,将创建一个包含一些空表的新数据库。

Ever new user will get a new database and ever new database will be the same tables inside of it, but the information that each user will store will be different. 每个新用户都将获得一个新数据库,并且新数据库将在其中包含相同的表,但是每个用户将存储的信息将有所不同。

the reason I believe I need this due to if the user no longer want to use my system I can provide them the information that they stored on my DB and then drop the DB and tables with great ease 之所以我相信我需要这个原因,是因为如果用户不再想要使用我的系统,我可以向他们提供他们存储在我的数据库中的信息,然后轻松地删除数据库和表

what I'm looking for is something like the mysql_create_db() in php 我正在寻找的是类似于php中的mysql_create_db()

Dont you think that you are making a simple system complex? 您是否不认为自己使一个简单的系统变得复杂? The way you are thinking is not scalable. 您的思维方式不可扩展。 For example, if you have thousands of user you have to create same amount of database tables!! 例如,如果您有成千上万的用户,则必须创建相同数量的数据库表! Where most of the tables might be of no use. 大多数表可能没有用。 That is definitely ridiculous... 那绝对是荒谬的...

If you just want to achieve the followings 如果您仅想实现以下目标

  • Each user will have his own data. 每个用户将拥有自己的数据。
  • User may want to export data. 用户可能要导出数据。
  • If users close his account you will delete all his data 如果用户关闭他的帐户,您将删除他的所有数据

then you better think the whole as a single application with a single database. 那么您最好将整体视为具有单个数据库的单个应用程序。 Design your database accordingly and better look for the best DRY practices of rails to implement that. 相应地设计数据库,并更好地寻找rails的最佳DRY实践以实现这一点。

This is not a good way to store users in a relational database, especially when using an application framework like ruby on rails which depends on your following convention over configuration. 这不是将用户存储在关系数据库中的好方法,尤其是在使用诸如ruby on rails之类的应用程序框架时,这取决于您对配置的以下约定。

Have one user Model and use the Devise and then Cancan gems to manage roles and permissions. 拥有一个用户模型,并使用Devise和Cancan gem管理角色和权限。 There's no need to reinvent the wheel here and that's just what this would be doing. 无需在这里重新发明轮子,这就是要做的事情。

If there are other considerations such as size or performance, please spell them out in more detail. 如果还有其他考虑因素,例如尺寸或性能,请详细说明。 The reasons you give (ease of management) would not be a good reason to go down that path. 您给出的理由(易于管理)并不是走这条路的好理由。

It's an interesting idea and has uses in other areas, but really not so good for your standard user tables. 这是一个有趣的想法,并且已在其他领域使用,但对于标准用户表而言确实不那么好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM