Ejemplo n.º 1
0
        // TODO -- think this one might have to change w/ FK's
        public void WritePatch(DocumentMapping mapping, IDDLRunner runner)
        {
            runner.Apply(mapping, $"ALTER TABLE {mapping.Table.QualifiedName} ADD COLUMN {ColumnName} {PgType};");

            var jsonField = new JsonLocatorField(_enumStorage, Members);

            // HOKEY, but I'm letting it pass for now.
            var sqlLocator = jsonField.SqlLocator.Replace("d.", "");

            runner.Apply(mapping, $"update {mapping.Table.QualifiedName} set {ColumnName} = {sqlLocator}");
        }
Ejemplo n.º 2
0
        public void CreatePatch(IDDLRunner runner)
        {
            TableDiff.CreatePatch(_mapping, runner);

            if (HasFunctionChanged())
            {
                _existing.FunctionDropStatements.Each(x => runner.Apply(this, x));

                runner.Apply(this, expectedUpsertFunction());
            }

            IndexChanges.Each(x => runner.Apply(this, x));
        }
Ejemplo n.º 3
0
 public void WritePatch(IDocumentSchema schema, IDDLRunner runner)
 {
     if (functionShouldBeReloaded(schema))
     {
         runner.Apply(this, GenerateFunction());
     }
 }
Ejemplo n.º 4
0
        public void GenerateSchemaObjectsIfNecessary(AutoCreate autoCreateSchemaObjectsMode, IDocumentSchema schema,
                                                     IDDLRunner runner)
        {
            if (_checked)
            {
                return;
            }


            var shouldReload = functionShouldBeReloaded(schema);

            if (!shouldReload)
            {
                _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);
            }

            runner.Apply(this, GenerateFunction());
        }
        public void GenerateSchemaObjectsIfNecessary(AutoCreate autoCreateSchemaObjectsMode, IDocumentSchema schema, IDDLRunner runner)
        {
            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);

                    runner.Apply(this, writer.ToString());
                }
            }
        }
Ejemplo n.º 6
0
        public void CreatePatch(DocumentMapping mapping, IDDLRunner runner)
        {
            var systemFields = new string[] { DocumentMapping.LastModifiedColumn, DocumentMapping.DotNetTypeColumn, DocumentMapping.VersionColumn };

            var missingNonSystemFields = Missing.Where(x => !systemFields.Contains(x.Name)).ToArray();
            var fields = missingNonSystemFields.Select(x => mapping.FieldForColumn(x.Name)).ToArray();

            if (fields.Length != missingNonSystemFields.Length)
            {
                throw new InvalidOperationException("The expected columns did not match with the DocumentMapping");
            }


            var missingSystemColumns = Missing.Where(x => systemFields.Contains(x.Name)).ToArray();

            if (missingSystemColumns.Any())
            {
                missingSystemColumns.Each(col =>
                {
                    var patch =
                        $"alter table {_tableName.QualifiedName} add column {col.ToDeclaration(col.Name.Length + 1)};";

                    runner.Apply(this, patch);
                });
            }


            fields.Each(x => x.WritePatch(mapping, runner));
        }
Ejemplo n.º 7
0
 public static void OwnershipToTable(this IDDLRunner runner, StoreOptions options, TableName table)
 {
     if (options.OwnerName.IsNotEmpty())
     {
         runner.Apply(table, $"ALTER TABLE {table.QualifiedName} OWNER TO {options.OwnerName};");
     }
 }
Ejemplo n.º 8
0
 private void runDependentScripts(IDDLRunner runner)
 {
     DependentScripts.Each(script =>
     {
         var sql = SchemaBuilder.GetSqlScript(_mapping.DatabaseSchemaName, script);
         runner.Apply(this, sql);
     });
 }
Ejemplo n.º 9
0
 public void WritePatch(IDocumentSchema schema, IDDLRunner runner)
 {
     if (!schema.DbObjects.TableExists(Table))
     {
         var sqlScript = SchemaBuilder.GetSqlScript(Table.Schema, "mt_hilo");
         runner.Apply(this, sqlScript);
     }
 }
Ejemplo n.º 10
0
        private void rebuildTableAndUpsertFunction(IDocumentSchema schema, IDDLRunner runner)
        {
            var writer = new StringWriter();

            WriteSchemaObjects(schema, writer);

            var sql = writer.ToString();

            runner.Apply(this, sql);
        }
Ejemplo n.º 11
0
        public void WritePatch(IDocumentSchema schema, IDDLRunner runner)
        {
            var tableExists = schema.DbObjects.TableExists(_parent.Table);

            if (tableExists)
            {
                return;
            }

            runner.Apply(this, SchemaBuilder.GetSqlScript(_parent.DatabaseSchemaName, "mt_stream"));
        }
Ejemplo n.º 12
0
        public static void Drop(this IDDLRunner runner, object subject, DbObjectName table)
        {
            var sql = $"drop table if exists {table.QualifiedName} cascade;";

            runner.Apply(subject, sql);
        }
Ejemplo n.º 13
0
        public static void RemoveColumn(this IDDLRunner runner, object subject, DbObjectName table, string columnName)
        {
            var sql = $"alter table if exists {table.QualifiedName} drop column if exists {columnName};";

            runner.Apply(subject, sql);
        }