Exemple #1
0
        /// <summary>
        /// Inits Event Store
        /// </summary>
        public Exercise09Projections()
        {
            databaseConnection = PostgresDbConnectionProvider.GetFreshDbConnection();

            var databaseProvider =
                new PostgresqlDatabaseProvider(databaseConnection)
            {
                SchemaName = typeof(Exercise09Projections).Name
            };

            var migrationsAssembly = typeof(Exercise09Projections).Assembly;
            var migrator           = new SimpleMigrator(migrationsAssembly, databaseProvider);

            migrator.Load();
            migrator.MigrateToLatest();

            // Create Event Store
            eventStore = new EventStore(databaseConnection);

            eventStore.AddProjection(new UserDashboardProjection(databaseConnection));

            // Initialize Event Store
            eventStore.Init();

            userRepository  = new Repository <User>(eventStore);
            orderRepository = new Repository <Order>(eventStore);
        }
Exemple #2
0
        public void UpgradeDataBase()
        {
            // start conecxão da db.
            using (var connection = new NpgsqlConnection(cnn))
            {
                var databaseProvider = new PostgresqlDatabaseProvider(connection);
                var migrator         = new SimpleMigrator(assemblyTo, databaseProvider);

                // carregar todos os estados de versões da base de dados.
                migrator.Load();

                // quando existir uma versão já ativa, inicie as migrações apratir de uma versão especifica.
                //migrator.Baseline(10);

                // verificar se a versão da db atual é diferente da ultima versão dos arquivos de migrações.
                if (migrator.CurrentMigration.Version != migrator.LatestMigration.Version)
                {
                    // atualizar db para ultima versão.
                    migrator.MigrateToLatest();

                    // atualizar db até o arquivo de migração numero 11.
                    //migrator.MigrateTo(11);
                }

                Assert.IsTrue(migrator.CurrentMigration.Version == migrator.LatestMigration.Version);
            }
        }
        /// <summary>
        /// Inits Event Store
        /// </summary>
        public Exercise08Snapshots()
        {
            databaseConnection = PostgresDbConnectionProvider.GetFreshDbConnection();

            var databaseProvider =
                new PostgresqlDatabaseProvider(databaseConnection)
            {
                SchemaName = typeof(Exercise08Snapshots).Name
            };

            var migrationsAssembly = typeof(Exercise08Snapshots).Assembly;
            var migrator           = new SimpleMigrator(migrationsAssembly, databaseProvider);

            migrator.Load();
            migrator.MigrateToLatest();

            // Create Event Store
            eventStore = new EventStore(databaseConnection);

            var userSnapshot = new SnapshotToTable <User>(
                databaseConnection,
                @"TODO write upsert here");

            eventStore.AddSnapshot(userSnapshot);

            // Initialize Event Store
            eventStore.Init();

            repository = new Repository <User>(eventStore);
        }
        /// <summary>
        /// Inits Event Store
        /// </summary>
        public Exercise08Snapshots()
        {
            databaseConnection = PostgresDbConnectionProvider.GetFreshDbConnection();

            var databaseProvider =
                new PostgresqlDatabaseProvider(databaseConnection)
            {
                SchemaName = typeof(Exercise08Snapshots).Name
            };

            var migrationsAssembly = typeof(Exercise08Snapshots).Assembly;
            var migrator           = new SimpleMigrator(migrationsAssembly, databaseProvider);

            migrator.Load();
            migrator.MigrateToLatest();

            // Create Event Store
            eventStore = new EventStore(databaseConnection);

            var userSnapshot = new SnapshotToTable <User>(
                databaseConnection,
                @"INSERT INTO users (id, name, version) VALUES (@Id, @Name, @Version)
                 ON CONFLICT (id)
                 DO UPDATE SET name = @Name, version = @Version");

            eventStore.AddSnapshot(userSnapshot);

            // Initialize Event Store
            eventStore.Init();

            repository = new Repository <User>(eventStore);
        }
Exemple #5
0
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;

            var provider = new PostgresqlDatabaseProvider(new NpgsqlConnection(Configuration.GetConnectionString("DefaultConnection")));
            var migrator = new SimpleMigrator(typeof(Database.Migrations._001_Tokens).GetTypeInfo().Assembly, provider);

            migrator.Load();
            migrator.MigrateToLatest();
        }
Exemple #6
0
        public static void Main(string[] args)
        {
            var migrationsAssembly = Assembly.GetEntryAssembly();

            using (var connection = new NpgsqlConnection("Host=127.0.0.1;Username=doublemazeuser;Password=mycoolpass;Database=doublemaze"))
            {
                var databaseProvider = new PostgresqlDatabaseProvider(connection);
                var migrator         = new SimpleMigrator(migrationsAssembly, databaseProvider);
                migrator.Load();

                migrator.MigrateToLatest();
            }
        }
Exemple #7
0
        private static void Migrate()
        {
            var migrationsAssembly = typeof(Program).Assembly;

            using (var connection = new NpgsqlConnection(StoreFactory.ConnectionString))
            {
                var databaseProvider = new PostgresqlDatabaseProvider(connection);
                //new SimpleMigrator<X, B>(migrationsAssembly, null);
                var migrator = new SimpleMigrator(migrationsAssembly, databaseProvider);
                migrator.Load();
                migrator.MigrateToLatest();
            }
        }
Exemple #8
0
    private static void DoMigration(string connectionString, Action <SimpleMigrator> act)
    {
        // Connection to database
        using var db = new NpgsqlConnection(connectionString);

        // Get migration objects
        var provider = new PostgresqlDatabaseProvider(db)
        {
            SchemaName = AuthDb.Schema, TableName = "version_info"
        };
        var migrator = new SimpleMigrator(typeof(PostgreSqlDbClient).Assembly, provider, new ConsoleLogger());

        // Get all the migrations
        migrator.Load();

        // Perform the migration
        act(migrator);
    }
Exemple #9
0
        public void DowngradeDataBase()
        {
            int versionTo = 0;

            using (var connection = new NpgsqlConnection(cnn))
            {
                var databaseProvider = new PostgresqlDatabaseProvider(connection);
                var migrator         = new SimpleMigrator(assemblyTo, databaseProvider);

                // carregar todos os estados de versões da base de dados.
                migrator.Load();

                // a versão da db atual deve ser maior que a versão versionTo.
                if (migrator.CurrentMigration.Version > versionTo)
                {
                    // versão da db para qual deseja voltar.
                    migrator.MigrateTo(versionTo);
                }

                Assert.IsTrue(migrator.CurrentMigration.Version == migrator.LatestMigration.Version);
            }
        }
Exemple #10
0
        public void RunMigrations(DbService db)
        {
            var migrationsAssembly = typeof(Startup).Assembly;

            using (var pg = db.CreateConnection(longTimeout: true))
            {
                var databaseProvider = new PostgresqlDatabaseProvider(pg);
                var migrator         = new SimpleMigrator(migrationsAssembly, databaseProvider);
                migrator.Load();

                if (migrator.CurrentMigration == null || migrator.CurrentMigration.Version == 0)
                {
                    migrator.Baseline(2);
                }

                migrator.MigrateTo(5);

                if (migrator.LatestMigration.Version != migrator.CurrentMigration.Version)
                {
                    throw new Exception($"The newest available migration ({migrator.LatestMigration.Version}) != The current database migration ({migrator.CurrentMigration.Version}). You probably need to add a call to run the migration.");
                }
            }
        }