Creates import table

@param $schema

@return bool
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException
763403
protected function createTable($schema)
    {
        /** @var \DreamFactory\Core\Contracts\ServiceResponseInterface $rs */
        $rs = ServiceManager::handleRequest(
            $this->service->getName(),
            Verbs::POST,
            '_schema',
            [],
            [],
            ResourcesWrapper::wrapResources($schema)
        );

        if (in_array($rs->getStatusCode(), [HttpStatusCodes::HTTP_OK, HttpStatusCodes::HTTP_CREATED])) {
            return true;
        }

        $content = $rs->getContent();
        Log::error(
            'Failed to create table for importing CSV data: ' .
            (is_array($content) ? print_r($content, true) : $content)
        );
        throw new InternalServerErrorException('Failed to create table for importing CSV data. See log for details.');
    }
968659
def addImportSchema(self, schema):
        
        if not isinstance(schema, XMLSchema):
            raise TypeError, 'expecting a Schema instance'
        if schema.targetNamespace != self.targetNamespace:
            self._imported_schemas[schema.targetNamespace] = schema
        else:
            raise SchemaError, 'import schema bad targetNamespace'
1161724
protected function addConversionToSchema(array $schema): array
    {
        if (isset($schema['definitions']['conversionItem'])) {
            $modules = Utility::getModules();
            if (!empty($modules)) {
                $rule = $schema['definitions']['conversionItem']['properties']['modules']['additionalProperties']['anyOf'][0];
                foreach ($modules as $module) {
                    $schema['definitions']['conversionItem']['properties']['modules']['additionalProperties'] = false;
                    $schema['definitions']['conversionItem']['properties']['modules']['properties'][$module] = $rule;
                }
            }
        }

        return $schema;
    }
1055286
public function create($schema, $ifNotExists = true, $options = [])
    {
        if ($ifNotExists && $this->db->getDatabase(null, true)->tableExists($this->getName())) {
            return $this;
        }

        $defaultOptions = [
            'auto_increment' => 1
        ];

        $options = array_merge($defaultOptions, $options);
        $schema = $this->callSchema($schema);
        $columns = [];
        $comments = [];
        $primary = [];

        foreach ($schema->getColumns() as $column) {
            $column = $this->prepareColumn($column);

            $columns[$column->getName()] = SqlsrvGrammar::build(
                $column->getType() . $column->getLength(),
                $column->getAllowNull() ? null : 'NOT NULL',
                $column->getAutoIncrement() ? 'identity' : null,
                $column->getDefault() ? 'DEFAULT ' . $this->db->quote($column->getDefault()) : null
            );

            // Comment
            if ($column->getComment()) {
                $comments[$column->getName()] = $column->getComment();
            }

            // Primary
            if ($column->isPrimary()) {
                $primary[] = $column->getName();
            }
        }

        $keys = [];
        $keyComments = [];

        foreach ($schema->getIndexes() as $index) {
            if ($index->getType() === Key::TYPE_PRIMARY) {
                $primary = array_merge($primary, $index->getColumns());
            } else {
                $keys[$index->getName()] = [
                    'type' => strtoupper($index->getType()),
                    'name' => $index->getName(),
                    'columns' => $index->getColumns(),
                ];

                if ($index->getComment()) {
                    $keyComments[$index->getName()] = $index->getComment();
                }
            }
        }

        $options['comments'] = $comments;
        $options['key_comments'] = $keyComments;

        $query = SqlsrvGrammar::createTable(
            $this->getName(),
            $columns,
            $primary,
            $keys,
            false
        );

        $this->db->execute($query);
        $query = '';

        $comments = $options['comments'] ?? [];

        // Comments
        foreach ($comments as $name => $comment) {
            $query .= ";\n" . SqlsrvGrammar::comment(
                'COLUMN',
                $this->db->replacePrefix($this->getName()),
                $name,
                $comment
            );
        }

        if ($query) {
            $this->db->execute($query);
        }

        return $this->reset();
    }
65655
public static function create( $schema, $returnHtml = true )
    {
        $_schema = $schema;

        if ( !is_array( $_schema ) || ( is_string( $_schema ) && false === ( $_schema = json_decode( $schema, true ) ) ) )
        {
            throw new \InvalidArgumentException( 'You must provide a schema in either an array or a JSON string.' );
        }

        return static::_buildFormFields( $_schema, $returnHtml );
    }
1224581
public function visitSchema(Schema $schema)
    {
        $result = $this->result($schema);
        if (null !== $result) {
            return $result;
        }

        $result = $this->register($schema, $this->createResult());

        foreach ($schema->constraints() as $constraint) {
            $result = $result->merge($constraint->accept($this));
        }

        if ($result->isValid()) {
            $result->addMatch($this->createMatch($schema));
        }

        return $result;
    }
417189
public function setSchema($schema) {
        if(!$this->setModified('schema', $schema)->isModified()) {
            return $this;
        }
		$this->schema = $schema;
		return $this;
    }
587174
public static function createContent(SchemaInterface $schema, AbstractTable $table): self
    {
        $context = new self();
        $context->class = $schema->getClass();
        $context->database = $schema->getDatabase();
        $context->table = $schema->getTable();
        $context->role = $schema->getRole();

        $context->schema = $table;

        return $context;
    }
1311815
public function create($schema, $ifNotExists = true, $options = [])
    {
        $defaultOptions = [
            'auto_increment' => 1,
            'sequences' => [],
        ];

        $options = array_merge($defaultOptions, $options);
        $schema = $this->callSchema($schema);
        $columns = [];
        $comments = [];
        $primary = [];

        foreach ($schema->getColumns() as $column) {
            $column = $this->prepareColumn($column);

            $columns[$column->getName()] = PostgresqlGrammar::build(
                $column->getType() . $column->getLength(),
                $column->getAllowNull() ? null : 'NOT NULL',
                $column->isPrimary()
                    ? null
                    : 'DEFAULT ' . $this->db->getQuery(true)->validValue($column->getDefault())
            );

            // Comment
            if ($column->getComment()) {
                $comments[$column->getName()] = $column->getComment();
            }

            // Primary
            if ($column->isPrimary()) {
                $primary[] = $column->getName();
            }
        }

        $keys = [];
        $keyComments = [];

        foreach ($schema->getIndexes() as $index) {
            if ($index->getType() === Key::TYPE_PRIMARY) {
                $primary = array_merge($primary, $index->getColumns());
            } else {
                $keys[$index->getName()] = [
                    'type' => strtoupper($index->getType()),
                    'name' => $index->getName(),
                    'columns' => $index->getColumns(),
                ];

                if ($index->getComment()) {
                    $keyComments[$index->getName()] = $index->getComment();
                }
            }
        }

        $options['comments'] = $comments;
        $options['key_comments'] = $keyComments;

        $inherits = isset($options['inherits']) ? $options['inherits'] : null;
        $tablespace = isset($options['tablespace']) ? $options['tablespace'] : null;

        $query = PostgresqlGrammar::createTable(
            $this->getName(),
            $columns,
            $primary,
            $keys,
            $inherits,
            $ifNotExists,
            $tablespace
        );

        $comments = isset($options['comments']) ? $options['comments'] : [];
        $keyComments = isset($options['key_comments']) ? $options['key_comments'] : [];

        // Comments
        foreach ($comments as $name => $comment) {
            $query .= ";\n" . PostgresqlGrammar::comment('COLUMN', $this->getName(), $name, $comment);
        }

        foreach ($keyComments as $name => $comment) {
            $query .= ";\n" . PostgresqlGrammar::comment('INDEX', 'public', $name, $comment);
        }

        DatabaseHelper::batchQuery($this->db, $query);

        return $this->reset();
    }
634862
public static function create(Schema $schema, $snapshotName = 'snapshot')
    {
        $snapshot = $schema->createTable($snapshotName);

        $snapshot->addColumn('aggregate_type', 'string');
        $snapshot->addColumn('aggregate_id', 'string');
        $snapshot->addColumn('last_version', 'integer');
        $snapshot->addColumn('created_at', 'string');
        $snapshot->addColumn('aggregate_root', 'blob');

        $snapshot->addIndex(['aggregate_type', 'aggregate_id']);
    }
370593
public function finish_table_import($tablename) {
        $table  = $this->schema->getTable($tablename);
        $fields = $table->getFields();
        foreach ($fields as $field) {
            if ($field->getSequence()) {
                $this->manager->reset_sequence($tablename);
                return;
            }
        }
        if ($this->transactionmode == 'pertable') {
            $this->transaction->allow_commit();
        }
    }
1287478
public function update($schema)
    {
        $schema = $this->callSchema($schema);

        foreach ($schema->getColumns() as $column) {
            if ($this->hasColumn($column->getName())) {
                $this->modifyColumn($column);
            } else {
                $this->addColumn($column);
            }
        }

        foreach ($schema->getIndexes() as $index) {
            $this->addIndex($index);
        }

        return $this->reset();
    }
768526
public function assemble($document, Schema $schema)
    {
        $entityClass = $schema->entityClass;
        $model = Ioc::make($entityClass);

        foreach ($document as $field => $value) {
            $fieldType = $schema->fields[$field] ?? null;

            if ($fieldType && 'schema.' == substr($fieldType, 0, 7)) {
                $value = $this->assembleDocumentsRecursively($value, substr($fieldType, 7));
            }

            $model->$field = $value;
        }

        $entity = $this->morphingTime($model);

        return $this->prepareOriginalAttributes($entity);
    }
1262377
public function upgradeSchema(Schema $schema)
    {
        $table = $schema->getTable('FileImageThumbnailPaths');
        if ($table->hasIndex('thumbnailPathID')) {
            $table->dropIndex('thumbnailPathID');
        }
        if (!$table->hasColumn('thumbnailFormat')) {
            $table->addColumn(
                'thumbnailFormat',
                'string',
                [
                    'notnull' => true,
                    'default' => '',
                    'length' => 5,
                ]
            );
            $table->setPrimaryKey([
                'fileID',
                'fileVersionID',
                'thumbnailTypeHandle',
                'storageLocationID',
                'thumbnailFormat',
            ]);
        }
    }
263308
public function validateWithSchemas(Schemas $schemas)
    {
        // create the schemas collection, then validate the document against the schemas
        if (! $schemas->count()) {
            return;
        }
        // build the unique importing schema
        $xsd = $schemas->getImporterXsd();
        LibXmlException::useInternalErrors(function () use ($xsd) {
            $this->document->schemaValidateSource($xsd);
        });
    }
1113488
public function addSchema(string $schema) : void
    {
        $work = $schema;
        if ($work{0} != '/') {
            $work = getcwd()."/$work";
        }
        if (!file_exists($work)) {
            $this->notice("`\"$schema\"` for `{$this->database}` not found, skipping.");
            return;
        }
        $this->schemas[] = file_get_contents($work);
        $this->success("Loaded $schema.");
    }
728347
public function setSchema($schema)
    {
        $this->connect();
        $this->_connection->exec('SET search_path TO ' . $this->_connection->quote($schema));
    }