rebus-org / Rebus.SqlServer

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

Make it easy to deploy SQL Schema at deploy time, not run time (to use dedicate login, separate from application login) #9

Closed trreeves closed 7 years ago

trreeves commented 7 years ago

Typically in a web application, the SQL login used by the application will have restricted permissions, obviously for security reasons. Usually creating SQL schema is required to happen upfront, when the application is being deployed (and often performed in scripts, i.e. Powershell).

I have written some methods that make this easy to achieve for the different SQL persistence types, something like...

    namespace Rebus.SqlServer.Transport
    {
        public static class SchemaInstaller
        {
            public static void EnsureInstalled(string connectionString, string tableName)
            {
                EnsureInstalled(connectionString, tableName, LogLevel.Debug);
            }

            public static void EnsureInstalled(string connectionString, string tableName, LogLevel logLevel)
            {
                var loggerFactory = new ConsoleLoggerFactory(true);
                loggerFactory.MinLevel = logLevel;

                EnsureInstalled(connectionString, tableName, loggerFactory);
            }

            public static void EnsureInstalled(string connectionString, string tableName, IRebusLoggerFactory rebusLoggerFactory)
            {
                var connectionProvider = new DbConnectionProvider(connectionString, rebusLoggerFactory);
                var taskFactory = new TplAsyncTaskFactory(rebusLoggerFactory);

                using (var transport = new SqlServerTransport(connectionProvider, tableName, null, rebusLoggerFactory, taskFactory))
                {
                    transport.EnsureTableIsCreated();
                }
            }
        }
    }

If you think this is of value I can submit a PR.

Cheers.

mookid8000 commented 7 years ago

It's a pretty good idea, but if such thing was provided for the SQL Server persistence implementation I would probably expect it to exist for PostgreSQL, Azure Service Bus, MSMQ, etc. too.

I'll park this under "great ideas, need to boil a little longer though" for now 😄 It can always be provided in the form of an external NuGet package that provides an API similar to the one you posted.

trreeves commented 7 years ago

Yeah sure, I understand. Just have that requirement in mind - I don't think we're that special in wanting to do the deploy this way.