public void GenerateSchemaObjectsIfNecessary(AutoCreate autoCreateSchemaObjectsMode, IDocumentSchema schema, SchemaPatch patch)
        {
            if (_checkedSchema) return;

            _checkedSchema = true;

            var tableExists = schema.DbObjects.TableExists(_parent.Table);

            if (tableExists) return;

            if (autoCreateSchemaObjectsMode == AutoCreate.None)
            {
                throw new InvalidOperationException(
                    "The EventStore schema objects do not exist and the AutoCreateSchemaObjects is configured as " +
                    autoCreateSchemaObjectsMode);
            }

            lock (_locker)
            {
                if (!schema.DbObjects.TableExists(_parent.Table))
                {
                    var writer = new StringWriter();

                    writeBasicTables(schema, writer);

                    patch.Updates.Apply(this, writer.ToString());
                }
            }
        }
Example #2
0
        public void GenerateSchemaObjectsIfNecessary(AutoCreate autoCreateSchemaObjectsMode, IDocumentSchema schema, SchemaPatch patch)
        {
            if (_checked) return;

            _checked = true;

            if (!schema.DbObjects.TableExists(Table))
            {
                if (_options.AutoCreateSchemaObjects == AutoCreate.None)
                {
                    throw new InvalidOperationException($"Hilo table is missing, but {nameof(StoreOptions.AutoCreateSchemaObjects)} is {_options.AutoCreateSchemaObjects}");
                }

                WritePatch(schema, patch);
            }
        }
Example #3
0
        public void GenerateSchemaObjectsIfNecessary(AutoCreate autoCreateSchemaObjectsMode, IDocumentSchema schema, SchemaPatch patch)
        {
            if (Checked) return;

            Checked = true;

            var diff = createFunctionDiff(schema);

            if (!diff.HasChanged) return;

            if (autoCreateSchemaObjectsMode == AutoCreate.None)
            {
                throw new InvalidOperationException($"{_function.QualifiedName} function is missing, but {nameof(StoreOptions.AutoCreateSchemaObjects)} is {autoCreateSchemaObjectsMode}");
            }

            diff.WritePatch(schema.StoreOptions, patch);
        }
Example #4
0
        public void GenerateSchemaObjectsIfNecessary(AutoCreate autoCreateSchemaObjectsMode, IDocumentSchema schema, SchemaPatch patch)
        {
            if (_checked) return;


            var diff  = functionDiff(schema);
            if (!diff.HasChanged)
            {
                _checked = true;
                return;
            }


            if (autoCreateSchemaObjectsMode == AutoCreate.None)
            {
                string message =
                    $"The transform function {Function.QualifiedName} and cannot be created dynamically unless the {nameof(StoreOptions)}.{nameof(StoreOptions.AutoCreateSchemaObjects)} is higher than \"None\". See http://jasperfx.github.io/marten/documentation/documents/ for more information";
                throw new InvalidOperationException(message);
            }

            diff.WritePatch(schema.StoreOptions, patch);
        }
Example #5
0
        public void GenerateSchemaObjectsIfNecessary(AutoCreate autoCreateSchemaObjectsMode, IDocumentSchema schema, SchemaPatch patch)
        {
            if (Checked || autoCreateSchemaObjectsMode == AutoCreate.None)
            {
                return;
            }

            Checked = true;

            var diff = createFunctionDiff(schema);

            if (!diff.HasChanged)
            {
                return;
            }

            if (autoCreateSchemaObjectsMode == AutoCreate.None)
            {
                throw new InvalidOperationException($"{_function.QualifiedName} function is missing, but {nameof(StoreOptions.AutoCreateSchemaObjects)} is {autoCreateSchemaObjectsMode}");
            }

            diff.WritePatch(schema.StoreOptions, patch);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleAuthMartenOptions"/> class.
        /// </summary>
        /// <param name="connectionString">The connection string</param>
        /// <param name="logger">The logger.</param>
        /// <param name="searchPath">The schema name</param>
        /// <param name="autoCreate">Schema creation options</param>
        public SimpleAuthMartenOptions(
            string connectionString,
            IMartenLogger?logger  = null,
            string searchPath     = "",
            AutoCreate autoCreate = AutoCreate.CreateOrUpdate)
        {
            Serializer <CustomJsonSerializer>();
            Connection(connectionString);
            if (logger != null)
            {
                Logger(logger);
            }
            Schema.Include <SimpleAuthRegistry>();
            if (!string.IsNullOrWhiteSpace(searchPath))
            {
                DatabaseSchemaName = searchPath;
            }

            Policies.DisableInformationalFields().AllDocumentsAreMultiTenanted();
            AutoCreateSchemaObjects             = autoCreate;
            GeneratedCodeMode                   = TypeLoadMode.Static;
            Advanced.DuplicatedFieldEnumStorage = EnumStorage.AsString;
            Advanced.DuplicatedFieldUseTimestampWithoutTimeZoneForDateTime = true;
        }
Example #7
0
        public SchemaPatchDifference CreatePatch(DbDataReader reader, SchemaPatch patch, AutoCreate autoCreate)
        {
            if (!reader.Read() || reader.GetInt32(0) == 0)
            {
                Write(patch.Rules, patch.UpWriter);
                return(SchemaPatchDifference.Create);
            }

            return(SchemaPatchDifference.None);
        }
        public void should_not_throw_exception_on_assertion(SchemaPatchDifference difference, AutoCreate autoCreate)
        {
            var patch  = new SchemaPatch(new DdlRules());
            var table1 = new Table(new DbObjectName("public", "sometable1"));

            patch.Log(table1, difference);

            patch.AssertPatchingIsValid(autoCreate);
        }
        public void should_throw_exception_on_assertion(SchemaPatchDifference difference, AutoCreate autoCreate)
        {
            var patch  = new SchemaPatch(new DdlRules());
            var table1 = new Table(new DbObjectName("public", "sometable1"));

            patch.Log(table1, difference);

            Exception <InvalidOperationException> .ShouldBeThrownBy(() =>
            {
                patch.AssertPatchingIsValid(autoCreate);
            });
        }
Example #10
0
        public SchemaPatchDifference CreatePatch(DbDataReader reader, SchemaPatch patch, AutoCreate autoCreate)
        {
            var diff = fetchDelta(reader, patch.Rules);

            if (diff == null)
            {
                Write(patch.Rules, patch.UpWriter);
                WriteDropStatement(patch.Rules, patch.DownWriter);

                return(SchemaPatchDifference.Create);
            }

            if (diff.AllNew)
            {
                Write(patch.Rules, patch.UpWriter);
                WriteDropStatement(patch.Rules, patch.DownWriter);

                return(SchemaPatchDifference.Create);
            }

            if (diff.HasChanged)
            {
                diff.WritePatch(patch);

                return(SchemaPatchDifference.Update);
            }

            return(SchemaPatchDifference.None);
        }
Example #11
0
        private void apply(ISchemaObject schemaObject, AutoCreate autoCreate, DbDataReader reader)
        {
            var difference = schemaObject.CreatePatch(reader, this, autoCreate);

            Migrations.Add(new ObjectMigration(schemaObject, difference));
        }
Example #12
0
 public SchemaMigrationException(AutoCreate autoCreate, IEnumerable <ISchemaObjectDelta> invalids) : base($"Cannot derive schema migrations for {invalids.Select(x => x.ToString()).Join(", ")} AutoCreate.{autoCreate}")
 {
 }
Example #13
0
        public void valid_asserts(AutoCreate autoCreate, SchemaPatchDifference[] differences)
        {
            var migration = migrationFor(differences);

            migration.AssertPatchingIsValid(autoCreate); // nothing thrown
        }
 public void GenerateSchemaObjectsIfNecessary(AutoCreate autoCreateSchemaObjectsMode, IDocumentSchema schema,
     SchemaPatch patch)
 {
 }
Example #15
0
 public void KeyEvents()
 {
     Username.KeyDown += (_, e) =>
     {
         if (e.KeyCode == Keys.Enter)
         {
             if (IsAdmin(Username.Text) && AccountsList[Username.Text] == Password.Text)
             {
                 ResetRetryTimer();
             }
             ButtonCodesReturn("Login");
         }
     };
     Password.KeyDown += (_, e) =>
     {
         if (e.KeyCode == Keys.Enter)
         {
             if (IsAdmin(Username.Text) && AccountsList[Username.Text] == Password.Text)
             {
                 ResetRetryTimer();
             }
             ButtonCodesReturn("Login");
         }
     };
     AddProduct.KeyDown += (_, e) =>
     {
         if (e.KeyCode == Keys.Enter)
         {
             if (AddProduct.Text == "")
             {
                 ToastNotification.Show(this, "Input product name first");
                 return;
             }
             if (SalesView.ReadOnly)
             {
                 ToastNotification.Show(this, ($"Can't add the product because you are on viewing mode only"));
                 return;
             }
             if (CurrentTable == null)
             {
                 ToastNotification.Show(SalesView, "No Available Sales or Selected Sales");
                 return;
             }
             if (CurrentTable.Columns.Contains(AddProduct.Text))
             {
                 ToastNotification.Show(SalesView, $"{AddProduct.Text} already existing");
                 return;
             }
             if (MessageBoxEx.Show($"Do you want to add this product: {AddProduct.Text}", "Add Product", MessageBoxButtons.YesNo) == DialogResult.Yes)
             {
                 CurrentTable.AddColumns(0, AddProduct.Text);
                 SetSalesView();
                 NotSaved = true;
             }
         }
     };
     AddAgent.KeyDown += (_, e) =>
     {
         if (e.KeyCode == Keys.Enter)
         {
             if (AddAgent.Text == "")
             {
                 ToastNotification.Show(this, "Input agent name first");
                 return;
             }
             if (SalesView.ReadOnly)
             {
                 ToastNotification.Show(this, ($"Can't add the agent because you are on viewing mode only"));
                 return;
             }
             if (Regex.IsMatch(AddAgent.Text, "[0-9]"))
             {
                 ToastNotification.Show(SalesView, "Numeric characters are invalid");
                 return;
             }
             if (CurrentTable == null)
             {
                 ToastNotification.Show(SalesView, "No Available Sales or Selected Sales");
                 return;
             }
             if (CurrentTable.Rows.Contains(AddAgent.Text))
             {
                 ToastNotification.Show(SalesView, $"{AddAgent.Text} is already existing");
                 return;
             }
             if (MessageBoxEx.Show($"Do you want to add this agent: {AddAgent.Text}", "Add Agent", MessageBoxButtons.YesNo) == DialogResult.Yes)
             {
                 CurrentTable.Rows.Add(AddAgent.Text);
                 SetSalesView();
                 NotSaved = true;
             }
         }
     };
     AccountControls.AddRange(new Control[] { AccountUsername, AccountPassword, AccountManagerName, AccountSecretAnswer, AccountSecretQuestion, AccountStatus });
     ManagerList.SelectedValueChanged += (_, ee) =>
     {
         AutoCreate.Value = false;
         AutoCreate.Refresh();
         SalesCalendar.SelectionStart = DateTime.Now;
         SalesCalendar.SelectionEnd   = DateTime.Now;
         SetSalesDataSet(ManagerList.SelectedItem.ToString(), this);
         StatusLabel.Text        = CurrentUser;
         MainStatusPanel.Visible = true;
     };
     AccountSecretQuestion.Items.AddRange(SecretQuestionList.ToArray());
     AccountStatus.Items.AddRange(new string[] { "admin", "Online", "Offline" });
     AccountsView.ReadOnly   = true;
     AccountsView.CellClick += (_, ee) =>
     {
         if (ee.RowIndex < 0)
         {
             return;
         }
         if (RegisterButton.Text == "Register")
         {
             ToastNotification.Show(this, "Can't edit data for now because you're in Create Account Mode");
             return;
         }
         BindFields(AccountsView.Rows[ee.RowIndex]);
     };
     AutoSave.ValueChanged += (_, e) =>
     {
         SaveButton.Enabled = !AutoSave.Value;
     };
     AccountsView.UserDeletedRow += (_, e) =>
     {
         if (AutoSave.Value)
         {
             ButtonCodesReturn("Save Changes");
         }
     };
     AccountsView.UserAddedRow += (_, e) =>
     {
         if (AutoSave.Value)
         {
             ButtonCodesReturn("Save Changes");
         }
     };
     AccountsView.CellValueChanged += (_, e) =>
     {
         if (AutoSave.Value)
         {
             ButtonCodesReturn("Save Changes");
         }
     };
     AccountsView.DataError += (_, e) =>
     {
         e.ThrowException = false;
     };
 }
Example #16
0
 public void GenerateSchemaObjectsIfNecessary(AutoCreate autoCreateSchemaObjectsMode, IDocumentSchema schema,
                                              SchemaPatch patch)
 {
 }
Example #17
0
 public void Apply(NpgsqlConnection connection, AutoCreate autoCreate, ISchemaObject schemaObject)
 {
     Apply(connection, autoCreate, new ISchemaObject[] { schemaObject });
 }
Example #18
0
        public SchemaPatchDifference CreatePatch(DbDataReader reader, SchemaPatch patch, AutoCreate autoCreate)
        {
            var existing = readExistingTable(reader);

            if (existing == null)
            {
                Write(patch.Rules, patch.UpWriter);
                patch.Rollbacks.Drop(this, Identifier);

                return(SchemaPatchDifference.Create);
            }

            var delta = new TableDelta(this, existing);

            if (delta.Matches)
            {
                return(SchemaPatchDifference.None);
            }

            if (delta.Extras.Any() || delta.Different.Any())
            {
                if (autoCreate == AutoCreate.All)
                {
                    delta.ForeignKeyMissing.Each(x => patch.Updates.Apply(this, x));
                    delta.ForeignKeyRollbacks.Each(x => patch.Rollbacks.Apply(this, x));
                    delta.ForeignKeyMissingRollbacks.Each(x => patch.Rollbacks.Apply(this, x));

                    Write(patch.Rules, patch.UpWriter);

                    return(SchemaPatchDifference.Create);
                }

                if (!delta.AlteredColumnTypes.Any())
                {
                    return(SchemaPatchDifference.Invalid);
                }
            }

            if (!delta.Missing.All(x => x.CanAdd))
            {
                return(SchemaPatchDifference.Invalid);
            }

            foreach (var missing in delta.Missing)
            {
                patch.Updates.Apply(this, missing.AddColumnSql(this));
                patch.Rollbacks.RemoveColumn(this, Identifier, missing.Name);
            }

            delta.AlteredColumnTypes.Each(x => patch.Updates.Apply(this, x));
            delta.AlteredColumnTypeRollbacks.Each(x => patch.Rollbacks.Apply(this, x));

            delta.IndexChanges.Each(x => patch.Updates.Apply(this, x));
            delta.IndexRollbacks.Each(x => patch.Rollbacks.Apply(this, x));

            delta.ForeignKeyChanges.Each(x => patch.Updates.Apply(this, x));
            delta.ForeignKeyRollbacks.Each(x => patch.Rollbacks.Apply(this, x));
            delta.ForeignKeyMissingRollbacks.Each(x => patch.Rollbacks.Apply(this, x));

            return(SchemaPatchDifference.Update);
        }
Example #19
0
 public void GenerateSchemaObjectsIfNecessary(AutoCreate autoCreateSchemaObjectsMode, IDocumentSchema schema, Action <string> executeSql)
 {
     _parent.GenerateSchemaObjectsIfNecessary(autoCreateSchemaObjectsMode, schema, executeSql);
 }