private Install ( string schemaGroup, SchemaObjectCollection schema ) : void | ||
schemaGroup | string | |
schema | SchemaObjectCollection | |
Результат | void |
/// <summary> /// Launch the insight schema setup. /// </summary> /// <param name="args"></param> static void Main(string[] args) { Console.WriteLine("Beginning to setup the database."); var connectionString = ConfigurationManager.ConnectionStrings["CodeWithMe"].ConnectionString; // Will actually create the database if it doesn't exist! SchemaInstaller.CreateDatabase(connectionString); // Invoke the schema installer to do magic. using (var db = new SqlConnection(connectionString)) { db.Open(); // create the installer to apply changes SchemaInstaller installer = new SchemaInstaller(db); new SchemaEventConsoleLogger().Attach(installer); // get the SQL from the embedded resources SchemaObjectCollection schema = new SchemaObjectCollection(Assembly.GetExecutingAssembly()); schema.StripPrintStatements = true; // install the schema // (This allows us to have multiple schemas in a single database. Pretty cool). installer.Install("CodeWithMe", schema); } Console.WriteLine(); Console.WriteLine("Done!"); }
// TODO: make database migration a separate task that is explicitly invoked on production public static void UpgradeSchema(string connectionString) { // Needs admin permission on database if the database does not yet exist - does nothing if it does SchemaInstaller.CreateDatabase(connectionString); // Do upgrade in the background for faster startup during development // (new Thread(() => { using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); // make sure our database exists SchemaInstaller installer = new SchemaInstaller(connection); new SchemaEventConsoleLogger().Attach(installer); // load the schema from the embedded resources in this project SchemaObjectCollection schema = new SchemaObjectCollection(); schema.Load(Assembly.GetExecutingAssembly()); // install the schema installer.Install("test", schema); } } // )).Start(); }
static void Main(string[] args) { SqlConnectionStringBuilder connectionString = new SqlConnectionStringBuilder("Database=.;Initial Catalog=InsightTest;Integrated Security=true"); SchemaInstaller.CreateDatabase(connectionString.ConnectionString); using (SqlConnection connection = new SqlConnection(connectionString.ConnectionString)) { connection.Open(); // make sure our database exists SchemaInstaller installer = new SchemaInstaller(connection); new SchemaEventConsoleLogger().Attach(installer); // load the schema from the embedded resources in this project SchemaObjectCollection schema = new SchemaObjectCollection(); schema.Load(Assembly.GetExecutingAssembly()); // install the schema Console.WriteLine("Installing"); installer.Install("BeerGarten", schema); // uninstall the schema if (args.Length > 0 && args[0].ToUpperInvariant() == "UNINSTALL") { Console.WriteLine("Uninstalling"); installer.Uninstall("BeerGarten"); } } }
public static void SetUpFixture() { #if !NET35 // insight.schema requires 4.0, so let's assume that in 35, the setup is already done // let's do all of our work in the test database if (!SchemaInstaller.DatabaseExists(BaseTest.ConnectionString)) SchemaInstaller.CreateDatabase(BaseTest.ConnectionString); var schema = new SchemaObjectCollection(Assembly.GetExecutingAssembly()); using (var connection = new SqlConnection(BaseTest.ConnectionString)) { connection.Open(); var installer = new SchemaInstaller(connection); installer.Install("Test", schema); } #endif }
static void Main() { var schema = new SchemaObjectCollection(); schema.Load(Assembly.GetExecutingAssembly()); // automatically create the database var connectionString = "server = .; database = PersonalFinance; integrated security = true;"; SchemaInstaller.CreateDatabase(connectionString); // automatically install it, or upgrade it using (var connection = new SqlConnection(connectionString)) { connection.Open(); var installer = new SchemaInstaller(connection); new SchemaEventConsoleLogger().Attach(installer); installer.Install("PersonalFinance", schema); } }
static void Main() { var schema = new SchemaObjectCollection(); schema.Load(Assembly.GetExecutingAssembly()); // automatically create the database var connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; var databaseName = "Thomas-test-db"; SchemaInstaller.CreateDatabase(connectionString); // automatically install it, or upgrade it using (var connection = new SqlConnection(connectionString)) { connection.Open(); var installer = new SchemaInstaller(connection); new SchemaEventConsoleLogger().Attach(installer); installer.Install(databaseName, schema); } }