rebus-org / Rebus.SqlServer

:bus: Microsoft SQL Server transport and persistence for Rebus
https://mookid.dk/category/rebus
Other
43 stars 42 forks source link

Support for schemas #3

Closed cleytonb closed 7 years ago

cleytonb commented 7 years ago

Hi!

Just discovered Rebus and I'm loving it! In my compary, we use schemas for every set of tables. For the queue table, we wanted to use something like "msg.QueueTable" but when I set this as the table name, the table generated is "dbo.msg.QueueTable".

Is there some way I can achieve this or should be implemented?

Best regards

mookid8000 commented 7 years ago

Unfortunately Rebus.SqlServer doesn't support schemas at the moment.

There's no reason, really, which it shouldn't support schemas. Only question is how it could be elegantly supported while not suddenly requiring a schema parameter everywhere.

mookid8000 commented 7 years ago

(but I guess the schema parameter could be made default to "dbo" on all configuration extensions – this way, calling code would not be broken too much, although it WOULD require recompilation for the default parameter to be picked up at all call sites)

cleytonb commented 7 years ago

By elegantly you exclude creating an overload or parsing tableName parameter? If one of these approaches are acceptable I could try to contribute.

mookid8000 commented 7 years ago

(....) parsing tableName parameter?

That's actually a pretty good idea... I guess you could parse the tableName and create some kind of TableName object out of it that holds both schema and table name, possibly by adopting the [] notation that T-SQL uses as delimiters...

...so that if you specify

.UseSqlServer(..., tableName: "whatever")

or even

.UseSqlServer(..., tableName: "[whatever]")

it would default to [dbo].[whatever], whereas explicitly specifying a schema

.UseSqlServer(..., tableName: "[rebus].[whatever]")

would result in using the whatever table in the rebus schema.

What do you think?

cleytonb commented 7 years ago

Seems good. Just added a pull request with this approach. I don't know how to use everything from Rebus yet, so I couldn't test everything (the unit tests are all passing).

mookid8000 commented 7 years ago

Support for schemas has been released in 2.1.0-b01 just now... it'll become 2.1.0 when it has been verified to work reliably