예제 #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}");
        }
예제 #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));
        }
예제 #3
0
 public void WritePatch(IDocumentSchema schema, IDDLRunner runner)
 {
     if (functionShouldBeReloaded(schema))
     {
         runner.Apply(this, GenerateFunction());
     }
 }
예제 #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());
                }
            }
        }
예제 #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));
        }
예제 #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};");
     }
 }
예제 #8
0
 private void runDependentScripts(IDDLRunner runner)
 {
     DependentScripts.Each(script =>
     {
         var sql = SchemaBuilder.GetSqlScript(_mapping.DatabaseSchemaName, script);
         runner.Apply(this, sql);
     });
 }
예제 #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);
     }
 }
예제 #10
0
        private void rebuildTableAndUpsertFunction(IDocumentSchema schema, IDDLRunner runner)
        {
            var writer = new StringWriter();

            WriteSchemaObjects(schema, writer);

            var sql = writer.ToString();

            runner.Apply(this, sql);
        }
        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"));
        }
예제 #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);
        }
예제 #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);
        }