PHPackages                             jeancodogno/doctrine-snowflake-id-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. jeancodogno/doctrine-snowflake-id-bundle

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

jeancodogno/doctrine-snowflake-id-bundle
========================================

Symfony bundle to automatically generate Snowflake IDs

v1.0.0(1y ago)4100↓50%MITPHPPHP ^8.2CI passing

Since Apr 20Pushed 1y ago1 watchersCompare

[ Source](https://github.com/jeancodogno/doctrine-snowflake-id-bundle)[ Packagist](https://packagist.org/packages/jeancodogno/doctrine-snowflake-id-bundle)[ RSS](/packages/jeancodogno-doctrine-snowflake-id-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (11)Versions (4)Used By (0)

❄️ Doctrine Snowflake ID Bundle
===============================

[](#️-doctrine-snowflake-id-bundle)

Symfony bundle to automatically assign Snowflake-based IDs to your Doctrine entities and documents. Supports both primary keys and any other custom fields using attributes.

 [![GitHub Workflow Status (main)](https://camo.githubusercontent.com/74f8cd3748bc545254ed7054e75beb414d31cb8ba070fef502f09b768a860a69/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a65616e636f646f676e6f2f646f637472696e652d736e6f77666c616b652d69642d62756e646c652f63692e796d6c3f6272616e63683d6d61696e266c6162656c3d5465737473)](https://github.com/jeancodogno/doctrine-snowflake-id-bundle/actions) [![Total Downloads](https://camo.githubusercontent.com/94d97615b2ffed5b62db105dd68586277fe96f4ec6c60566d732b3426d576a99/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a65616e636f646f676e6f2f646f637472696e652d736e6f77666c616b652d69642d62756e646c65)](https://packagist.org/packages/jeancodogno/doctrine-snowflake-id-bundle) [![Latest Version](https://camo.githubusercontent.com/7a2c9813e2498056acc8442142052b240970f16c9a33e5e03791e494d65778d5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a65616e636f646f676e6f2f646f637472696e652d736e6f77666c616b652d69642d62756e646c65)](https://packagist.org/packages/jeancodogno/doctrine-snowflake-id-bundle) [![License](https://camo.githubusercontent.com/e978dfb26463bc5dbb64a4e5cfbfa8381c17db05610bdbda885f28a3dd358d3b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a65616e636f646f676e6f2f646f637472696e652d736e6f77666c616b652d69642d62756e646c65)](https://packagist.org/packages/jeancodogno/doctrine-snowflake-id-bundle)

🚀 Features
----------

[](#-features)

✅ Assigns unique Snowflake IDs to your entities

🔄 Works for both primary keys and custom field using `#[SnowflakeColumn]` or `#[SnowflakeField]`

🧩 Seamlessly integrates with **Doctrine ORM** and **Doctrine ODM**

🧪 Fully testable

📦 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require jeancodogno/doctrine-snowflake-id-bundle
```

> The bundle uses autoconfiguration, no need to manually register it in `bundles.php`.

💡 Usage
-------

[](#-usage)

> PHP does not have a native type that supports big integers, so the variable must be defined as a `string`.

### 🔐 (Doctrine ORM) Using Snowflake ID Generator

[](#-doctrine-orm-using-snowflake-id-generator)

Use the `SnowflakeIdGenerator` class with Doctrine ORM’s custom ID generation:

```
use JeanCodogno\DoctrineSnowflakeIdBundle\SnowflakeIdGenerator;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class Product
{
    #[ORM\Id]
    #[ORM\Column(type: 'bigint')]
    #[ORM\GeneratedValue(strategy: 'CUSTOM')]
    #[ORM\CustomIdGenerator(class: SnowflakeIdGenerator::class)]
    private ?string $id = null;

    // ...
}
```

### ✳️ (Doctrine ORM) Assigning Snowflake ID to any column

[](#️-doctrine-orm-assigning-snowflake-id-to-any-column)

Use the `#[SnowflakeColumn]` attribute to mark any non-ID field for automatic generation:

```
use JeanCodogno\DoctrineSnowflakeIdBundle\Attributes\SnowflakeColumn;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class Product
{
    #[ORM\Column(type: 'bigint', unique: true)]
    #[SnowflakeColumn]
    private ?string $publicId = null;

    // ...
}
```

[![MongoDB logo](https://camo.githubusercontent.com/75c0e8908c40e84391b2fc850726ec18fad805e97a2da567ebfcfca05580f68d/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f64657669636f6e732f64657669636f6e2f69636f6e732f6d6f6e676f64622f6d6f6e676f64622d6f726967696e616c2e737667)](https://camo.githubusercontent.com/75c0e8908c40e84391b2fc850726ec18fad805e97a2da567ebfcfca05580f68d/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f64657669636f6e732f64657669636f6e2f69636f6e732f6d6f6e676f64622f6d6f6e676f64622d6f726967696e616c2e737667) (Doctrine ODM) Using Snowflake ID Generator
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#-doctrine-odm-using-snowflake-id-generator)

Use the `MongoSnowflakeIdGenerator` class with Doctrine ODM’s custom ID generation:

```
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use JeanCodogno\DoctrineSnowflakeIdBundle\IdGenerator\MongoSnowflakeIdGenerator;

#[ODM\Document(collection: 'products')]
class Product
{
    #[ODM\Id(strategy: 'CUSTOM', type: 'string', options: ['class' => MongoSnowflakeIdGenerator::class])]
    private ?string $id;

    // ...
```

[![MongoDB logo](https://camo.githubusercontent.com/75c0e8908c40e84391b2fc850726ec18fad805e97a2da567ebfcfca05580f68d/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f64657669636f6e732f64657669636f6e2f69636f6e732f6d6f6e676f64622f6d6f6e676f64622d6f726967696e616c2e737667)](https://camo.githubusercontent.com/75c0e8908c40e84391b2fc850726ec18fad805e97a2da567ebfcfca05580f68d/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f64657669636f6e732f64657669636f6e2f69636f6e732f6d6f6e676f64622f6d6f6e676f64622d6f726967696e616c2e737667) (Doctrine ODM) Assigning Snowflake ID to any field
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#-doctrine-odm-assigning-snowflake-id-to-any-field)

use the `#[SnowflakeColumn]` attribute to marky any field for automatic generation:

```
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use JeanCodogno\DoctrineSnowflakeIdBundle\Attributes\SnowflakeField;

#[ODM\Document(collection: 'products')]
class Product
{
    #[SnowflakeField]
    private ?string $public_id = null;

    // ...
```

🔧 Configuration
---------------

[](#-configuration)

By default, `DoctrineSnowflakeIdBundle` works without any configuration, using default values for `datacenterId`, `workerId`, and `startTimestamp`.

If you want to customize these values, you can define the following parameters in your Symfony configuration:

```
#config/services.yaml

parameters:
    snowflake_id.datacenter_id: 2         # Default: 0
    snowflake_id.worker_id: 7             # Default: 0
    snowflake_id.start_timestamp: 1672531200000  # Optional – e.g., Jan 1, 2023 in milliseconds
```

🧪 Testing
---------

[](#-testing)

You can test ID assignment with tools like PHPUnit or Pest. Snowflake IDs are generated before persist, ensuring uniqueness without collisions.

📜 License
---------

[](#-license)

This bundle is open-source software licensed under the [MIT license](https://choosealicense.com/licenses/mit/)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance48

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

2

Last Release

389d ago

Major Versions

v0.1.0 → v1.0.02025-04-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/d6f804f72a608930652873eed8f8a3ba745203937c91fc9a59101c119e727e92?d=identicon)[jeancodogno](/maintainers/jeancodogno)

---

Top Contributors

[![jeancodogno](https://avatars.githubusercontent.com/u/19910918?v=4)](https://github.com/jeancodogno "jeancodogno (27 commits)")

---

Tags

doctrinesnowflakedoctrine-bundledoctrine-odm-bundledoctrine-orm-bundle

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jeancodogno-doctrine-snowflake-id-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/jeancodogno-doctrine-snowflake-id-bundle/health.svg)](https://phpackages.com/packages/jeancodogno-doctrine-snowflake-id-bundle)
```

###  Alternatives

[hautelook/alice-bundle

Symfony bundle to manage fixtures with Alice and Faker.

19519.4M34](/packages/hautelook-alice-bundle)[damienharper/auditor-bundle

Integrate auditor library in your Symfony projects.

4542.8M](/packages/damienharper-auditor-bundle)[kimai/kimai

Kimai - Time Tracking

4.6k7.4k1](/packages/kimai-kimai)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1022.4k](/packages/rcsofttech-audit-trail-bundle)[ahmed-bhs/doctrine-doctor

Runtime analysis tool for Doctrine ORM integrated into Symfony Web Profiler. Unlike static linters, it analyzes actual query execution at runtime to detect performance bottlenecks, security vulnerabilities, and best practice violations during development with real execution context and data.

813.1k](/packages/ahmed-bhs-doctrine-doctor)[heymoon/doctrine-psql-enum

Store PHP native enums as PostgeSQL custom enum types

254.9k](/packages/heymoon-doctrine-psql-enum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
