setPrimaryKey example

// Mark all content type to be deleted, hopefully they will be redefined in the next step         foreach ($schema->getTables() as $table) {
            if (strpos($table->getName(), 's_custom_') === 0) {
                $schema->dropTable($table->getName());
            }
        }

        // Create all tables         foreach ($types as $type) {
            $myTable = $schema->createTable($type->getTableName());
            $myTable->addColumn('id', 'integer', ['unsigned' => true, 'autoincrement' => true]);
            $myTable->setPrimaryKey(['id']);

            /** @var Field $field */
            foreach ($type->getFields() as $field) {
                $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();
        


    /** * @param list<CustomEntityField> $fields */
    private function defineTable(Schema $schema, string $name, array $fields): void
    {
        $table = $this->createTable($schema$name);

        // Id columns do not need to be defined in the .xml, we do this automatically         $table->addColumn('id', Types::BINARY, ['length' => 16, 'fixed' => true]);
        $table->setPrimaryKey(['id']);

        // important: we add a `comment` to the table. This allows us to identify the custom entity modifications when run the cleanup         $table->setComment(self::COMMENT);

        // we have to add only fields, which are not marked as translated         $filtered = array_filter($fieldsfn (array $field) => ($field['translatable'] ?? false) === false);

        $filtered = array_filter($filteredfn (array $field) => !$this->isAssociation($field));

        $this->addColumns($schema$table$filtered);

        
$table->addColumn($this->timeCol, Types::INTEGER)->setNotnull(true);
                break;
            case 'sqlsrv':
                $table->addColumn($this->idCol, Types::TEXT)->setLength(128)->setNotnull(true);
                $table->addColumn($this->dataCol, Types::BLOB)->setNotnull(true);
                $table->addColumn($this->lifetimeCol, Types::INTEGER)->setUnsigned(true)->setNotnull(true);
                $table->addColumn($this->timeCol, Types::INTEGER)->setUnsigned(true)->setNotnull(true);
                break;
            default:
                throw new \DomainException(sprintf('Creating the session table is currently not implemented for PDO driver "%s".', $this->driver));
        }
        $table->setPrimaryKey([$this->idCol]);
        $table->addIndex([$this->lifetimeCol]$this->lifetimeCol.'_idx');
    }

    /** * Creates the table to store sessions which can be called once for setup. * * Session ID is saved in a column of maximum length 128 because that is enough even * for a 512 bit configured session.hash_function like Whirlpool. Session data is * saved in a BLOB. One could also use a shorter inlined varbinary column * if one was sure the data fits into it. * * @return void * * @throws \PDOException When the table already exists * @throws \DomainException When an unsupported PDO driver is used */
$table->addColumn('headers', Types::TEXT)
            ->setNotnull(true);
        $table->addColumn('queue_name', Types::STRING)
            ->setLength(190) // MySQL 5.6 only supports 191 characters on an indexed column in utf8mb4 mode             ->setNotnull(true);
        $table->addColumn('created_at', Types::DATETIME_IMMUTABLE)
            ->setNotnull(true);
        $table->addColumn('available_at', Types::DATETIME_IMMUTABLE)
            ->setNotnull(true);
        $table->addColumn('delivered_at', Types::DATETIME_IMMUTABLE)
            ->setNotnull(false);
        $table->setPrimaryKey(['id']);
        $table->addIndex(['queue_name']);
        $table->addIndex(['available_at']);
        $table->addIndex(['delivered_at']);
    }

    private function decodeEnvelopeHeaders(array $doctrineEnvelope): array
    {
        $doctrineEnvelope['headers'] = json_decode($doctrineEnvelope['headers'], true);

        return $doctrineEnvelope;
    }

    

        $types = [
            'mysql' => 'binary',
            'sqlite' => 'text',
        ];

        $table = $schema->createTable($this->table);
        $table->addColumn($this->idCol, $types[$this->getPlatformName()] ?? 'string', ['length' => 255]);
        $table->addColumn($this->dataCol, 'blob', ['length' => 16777215]);
        $table->addColumn($this->lifetimeCol, 'integer', ['unsigned' => true, 'notnull' => false]);
        $table->addColumn($this->timeCol, 'integer', ['unsigned' => true]);
        $table->setPrimaryKey([$this->idCol]);
    }
}
$table->addColumn($this->timeCol, Types::INTEGER)->setNotnull(true);
                break;
            case 'sqlsrv':
                $table->addColumn($this->idCol, Types::TEXT)->setLength(128)->setNotnull(true);
                $table->addColumn($this->dataCol, Types::BLOB)->setNotnull(true);
                $table->addColumn($this->lifetimeCol, Types::INTEGER)->setUnsigned(true)->setNotnull(true);
                $table->addColumn($this->timeCol, Types::INTEGER)->setUnsigned(true)->setNotnull(true);
                break;
            default:
                throw new \DomainException(sprintf('Creating the session table is currently not implemented for PDO driver "%s".', $this->driver));
        }
        $table->setPrimaryKey([$this->idCol]);
        $table->addIndex([$this->lifetimeCol]$this->lifetimeCol.'_idx');
    }

    /** * Creates the table to store sessions which can be called once for setup. * * Session ID is saved in a column of maximum length 128 because that is enough even * for a 512 bit configured session.hash_function like Whirlpool. Session data is * saved in a BLOB. One could also use a shorter inlined varbinary column * if one was sure the data fits into it. * * @return void * * @throws \PDOException When the table already exists * @throws \DomainException When an unsupported PDO driver is used */
$this->addTableToSchema($schema);
    }

    private function addTableToSchema(Schema $schema): void
    {
        $table = $schema->createTable('rememberme_token');
        $table->addColumn('series', Types::STRING, ['length' => 88]);
        $table->addColumn('value', Types::STRING, ['length' => 88]);
        $table->addColumn('lastUsed', Types::DATETIME_IMMUTABLE);
        $table->addColumn('class', Types::STRING, ['length' => 100]);
        $table->addColumn('username', Types::STRING, ['length' => 200]);
        $table->setPrimaryKey(['series']);
    }
}
$isSameDatabase = 1 < \func_num_args() ? func_get_arg(1) : static fn () => true;

        if (!$isSameDatabase($this->conn->executeStatement(...))) {
            return;
        }

        $table = $schema->createTable($this->table);
        $table->addColumn($this->idCol, 'string', ['length' => 64]);
        $table->addColumn($this->tokenCol, 'string', ['length' => 44]);
        $table->addColumn($this->expirationCol, 'integer', ['unsigned' => true]);
        $table->setPrimaryKey([$this->idCol]);
    }

    /** * Cleans up the table by removing all expired locks. */
    private function prune(): void
    {
        $sql = "DELETE FROM $this->table WHERE $this->expirationCol <= {$this->getCurrentTimestampStatement()}";

        $this->conn->executeStatement($sql);
    }

    
Home | Imprint | This part of the site doesn't use cookies.