meteor-rethinkdb icon indicating copy to clipboard operation
meteor-rethinkdb copied to clipboard

Auto create tables

Open lorensr opened this issue 10 years ago • 10 comments

Would be nice to automatically create tables that are declared but not present in db?

image

It will trip people up, even if explained in readme

lorensr avatar May 01 '15 23:05 lorensr

The rethinkdb driver doesn't autocreate tables. Why would Meteor do this?

Slava avatar May 02 '15 00:05 Slava

  1. To match the behavior of making Meteor Mongo.Collections
  2. Making things easier for developer

lorensr avatar May 02 '15 00:05 lorensr

Yeah, I don't know if this is what RethinkDB developers would expect. We can certainly do this, but it is kinda weird given that Rethink has an explicit command for creating tables.

Slava avatar May 02 '15 00:05 Slava

They might not expect it, but if they're declaring the table and it doesn't exist, they want it to exist, and so we're doing them a favor. IMO a net good

On Fri, May 1, 2015 at 5:33 PM, Slava Kim [email protected] wrote:

Yeah, I don't know if this is what RethinkDB developers would expect. We can certainly do this, but it is kinda weird given that Rethink has an explicit command for creating tables.

— Reply to this email directly or view it on GitHub https://github.com/Slava/meteor-rethinkdb/issues/4#issuecomment-98269706 .

lorensr avatar May 02 '15 00:05 lorensr

Or you misspelled the name of the table and now you have two tables. In mongo at least the collection is not created if nothing was written to it.

Slava avatar May 02 '15 00:05 Slava

Please add these to neumino/reglite#3.

zephraph avatar May 02 '15 03:05 zephraph

I might hope that developers will detect "misspelled table names" while they're still actively writing their code. It is unlikely that unwanted tables will be created in a production environment.

If the final word about this is indeed to not auto-create tables, I would suggest adding an option or method to make the code create the table, and not require a db-admin to dive into the database administration interface.

Something like

new Rethink.Table('players', { autocreate: true });

Or, inspired by the mongo _ensureIndex method:

Players = new Rethink.Table('players');
Players.ensureTableExists(true);

smeijer avatar May 08 '15 19:05 smeijer

Agree with above post. It's no fun when you have a ton of tables and every time you deploy your app you have to create them all manually.

ciwolsey avatar May 08 '15 21:05 ciwolsey

I think an autocreate flag might not be a bad idea. I just don't want to introduce any default behavior that is not expected from a raw RethinkDB driver. Especially, if it is modeled after MongoDB.

Slava avatar May 08 '15 22:05 Slava

I don't know if this should be in a separate issue, but should we also account for custom primary key field names? In RethinkDB when you create a table, there's an option to set the name of the auto-generated primary key, which if not set, defaults to id. This is different from MongoDB, which makes _id the only primary key.

rclai avatar May 23 '15 17:05 rclai