toSql example

/** * Creates the table to store lock keys which can be called once for setup. * * @throws DBALException When the table already exists */
    public function createTable(): void
    {
        $schema = new Schema();
        $this->configureSchema($schema);

        foreach ($schema->toSql($this->conn->getDatabasePlatform()) as $sql) {
            $this->conn->executeStatement($sql);
        }
    }

    /** * Adds the Table to the Schema if it doesn't exist. * * @param \Closure $isSameDatabase */
    public function configureSchema(Schema $schema/* , \Closure $isSameDatabase */): void
    {
        

    public function createTable(): void
    {
        $schema = new Schema();
        $this->addTableToSchema($schema);

        foreach ($schema->toSql($this->conn->getDatabasePlatform()) as $sql) {
            $this->conn->executeStatement($sql);
        }
    }

    /** * @param \Closure $isSameDatabase */
    public function configureSchema(Schema $schema, Connection $forConnection/* , \Closure $isSameDatabase */): void
    {
        if ($schema->hasTable($this->table)) {
            return;
        }
$myTable->addColumn($field->getName()$field->getType()::getDbalType()['notnull' => $field->isRequired()]);
            }

            $myTable->addColumn('created_at', 'datetime', []);
            $myTable->addColumn('updated_at', 'datetime', []);
        }

        $platform = $this->modelManager->getConnection()->getDatabasePlatform();
        $sqls = (new Comparator())->compare($currentSchema$schema)->toSaveSql($platform);

        if ($destructive) {
            $sqls = (new Comparator())->compare($currentSchema$schema)->toSql($platform);
        }

        foreach ($sqls as $sql) {
            $con->executeQuery($sql);
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.