Beispiel #1
0
        private static IServiceProvider CreateServices()
        {
            var dbParams = PostgresConnectionParams.FromEnv();

            return(new ServiceCollection()
                   .AddFluentMigratorCore()
                   .ConfigureRunner(rb => rb
                                    .AddPostgres()
                                    .WithGlobalConnectionString(dbParams.GetConnectionString())
                                    .ScanIn(typeof(Program).Assembly).For.Migrations())
                   .AddLogging(lb => lb.AddFluentMigratorConsole())
                   .BuildServiceProvider(false));
        }
        public static PostgresConnectionParams FromEnv()
        {
            var host = Environment.GetEnvironmentVariable("WEBCHAT_POSTGRES_HOST");
            var port = Environment.GetEnvironmentVariable("WEBCHAT_POSTGRES_PORT");
            var name = Environment.GetEnvironmentVariable("WEBCHAT_POSTGRES_NAME");
            var user = Environment.GetEnvironmentVariable("WEBCHAT_POSTGRES_USER");
            var pass = Environment.GetEnvironmentVariable("WEBCHAT_POSTGRES_PASS");

            var pgParams = new PostgresConnectionParams();

            pgParams.Host = host ?? pgParams.Host;
            pgParams.Port = port ?? pgParams.Port;
            pgParams.Name = name ?? pgParams.Name;
            pgParams.User = user ?? pgParams.User;
            pgParams.Pass = pass ?? pgParams.Pass;

            return(pgParams);
        }
Beispiel #3
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var dbParams = PostgresConnectionParams.FromEnv();

            optionsBuilder.UseNpgsql(dbParams.GetConnectionString());
        }