public void Dispose() { SqlScriptRunner.ExecCommand(_connection, "DROP SCHEMA public CASCADE;"); SqlScriptRunner.ExecCommand(_connection, "CREATE SCHEMA public;"); SqlScriptRunner.ExecCommand(_connection, "GRANT ALL ON SCHEMA public TO postgres;"); SqlScriptRunner.ExecCommand(_connection, "GRANT ALL ON SCHEMA public TO public;"); }
public static void seedFKData(DbConnection connection, DatabaseType type = DatabaseType.H2) { SqlScriptRunner.ExecCommand(connection, "CREATE TABLE Foo(x int, primary key (x));"); SqlScriptRunner.ExecCommand(connection, "CREATE TABLE Bar(y int, primary key (y));"); switch (type) { case DatabaseType.MS_SQL_SERVER: case DatabaseType.POSTGRES: SqlScriptRunner.ExecCommand(connection, "alter table Bar add constraint FK foreign key (y) references Foo;"); break; case DatabaseType.MYSQL: SqlScriptRunner.ExecCommand(connection, "alter table Bar add foreign key (y) references Foo(x);"); break; default: throw new InvalidOperationException("NOT SUPPORT"); } SqlScriptRunner.ExecCommand(connection, "INSERT INTO Foo (x) VALUES (42)"); SqlScriptRunner.ExecCommand(connection, "INSERT INTO Bar (y) VALUES (42)"); }