static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .WriteTo.Console() .CreateLogger(); Log.Information("Start testing PostgreConfigurer"); var workDirectory = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "postgres-oracle"); string username; SecureString password; Console.WriteLine("Username: "******"Enter password: "******"force"); if (isForceInstall || conf.IsInstalled) { if (conf.IsRunning) { conf.StopPostgres(); } conf.InstallPostgreSql(); ps.InstallPostgis(); } var sudoUser = new Npgsql.NpgsqlConnectionStringBuilder { Host = "127.0.0.1", Database = "postgres", Username = "******", Password = "******" }; if (!conf.IsRunning) { conf.RunPostgres(); } using (var contex = new Contex()) { bool isDbReady = !args.Any(x => x == "full_recreate"); //FIXME: Не работает /*try { * isDbReady &= contex.Database.CanConnect (); * } catch { * isDbReady = false; * }*/ if (!isDbReady) { Log.Information("Need recreation of database"); using (var connection = new Npgsql.NpgsqlConnection(sudoUser.ToString())) { connection.Open(); connection .DropDatabase("TestDatabase", true) .CreateUser(new NpgsqlUtils.CreateUserOptions { Username = "******", Password = "******" }) .CreateDatabase(new NpgsqlUtils.CreateDatabaseOptions { Name = "TestDatabase", Owner = "pilad", }); contex.Database.EnsureCreated(); connection.ChangeDatabase("testdatabase"); connection.Execute(ps.ActivatePostgisSql()); //TODO: Is nesessary? connection.Close(); } Log.Information("Recreating full scheme contex..."); } contex.Works.Add(new Work { first = "123", second = "dsa" }); contex.SaveChanges(); foreach (var work in contex.Works) { Log.Information("{first} {second}", work.first, work.second); } } //conf.StopPostgres(); System.Threading.Thread.Sleep(1000); }
public PostgisManager(PostgresqlAppManager manager) => Manager = manager;