Example #1
0
        /// <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");
				}
			}
		}
 /// <summary>
 /// Detach from the events of a SchemaInstaller
 /// </summary>
 /// <param name="installer">The installer to detach from</param>
 public void Detach (SchemaInstaller installer)
 {
     installer.DroppingObject -= _onSchemaChange;
     installer.UpdatingTable -= _onSchemaChange;
     installer.UpdatedTable -= _onSchemaChange;
     installer.CreatingObject -= _onSchemaChange;
     installer.CreatedObject -= _onSchemaChange;
 }
        /// <summary>
        /// Detach from the events of a SchemaInstaller
        /// </summary>
        /// <param name="installer">The installer to detach from</param>
        public void Detach (SchemaInstaller installer)
        {
			if (installer == null) throw new ArgumentNullException("installer");

            installer.DroppingObject -= _onSchemaChange;
            installer.CreatingObject -= _onSchemaChange;
            installer.CreatedObject -= _onSchemaChange;
			installer.DropFailed -= _onSchemaChange;
		}
Example #6
0
		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
		}
Example #7
0
        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);
            }
        }
Example #8
0
        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);
            }
        }
 /// <summary>
 /// Construct an event logger and attach it to a schema installer.
 /// </summary>
 /// <param name="installer">The installer to monitor</param>
 protected SchemaEventLogger (SchemaInstaller installer) : this()
 {
     Attach (installer);
 }
		/// <summary>
		/// Determine if this is a type of object that we can modify.
		/// </summary>
		/// <param name="type">The type of the object.</param>
		/// <returns>True if we know how to drop the object.</returns>
		internal bool CanModify(SchemaInstaller.InstallContext context, RecordingDbConnection connection)
		{
			return connection.DoNotLog(() => _implementation.CanModify(context, connection));
		}