Skip to content

Snowflake identifier #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: 1.x
Choose a base branch
from
Open

Snowflake identifier #5

wants to merge 10 commits into from

Conversation

puzzledpolymath
Copy link
Contributor

@puzzledpolymath puzzledpolymath commented Jul 16, 2025

🔍 What was changed

  • Added new behavior for Snowflake identifiers
  • Added defaults for configuring identifier values globally
  • Added test cases covering Snowflake identifiers
  • Added test cases for combining Snowflake, ULID and UUID identifiers
  • Documentation added to README detailing usage

🔔 Note

Pipelines will fail until the following PR's are merged and released.

📝 Checklist

💯 Test coverage
🟢 Psaml with empty baseline

  • How was this tested:
    • Unit tests added

@puzzledpolymath puzzledpolymath requested a review from a team July 16, 2025 07:00
@puzzledpolymath puzzledpolymath added the status:code review The pull request needs review. label Jul 16, 2025
@puzzledpolymath puzzledpolymath requested review from roxblnfk and removed request for a team July 16, 2025 07:04
@puzzledpolymath
Copy link
Contributor Author

@roxblnfk This is now passing after those couple of PR's were merged. Feedback welcomed

Comment on lines 36 to 37
private int $workerId = 0,
private int $processId = 0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like these fields shouldn't be hardcoded in attributes.

We can declare it as null|int<0, max> and use hardcoded values if they were specified.

Need to think how to provide this options from config (where ENVs can be used) to behavior implementation.

Copy link
Contributor Author

@puzzledpolymath puzzledpolymath Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I was writing these classes this did cross my mind. For instance SnowflakeInstagram and shardId is something developers will want more control over, if using the identifiers to their full potential/purpose.

The same applies for UUID's when specifying a node or localDomain.

I moved on pretty quick but the idea I had was trivial, a static class allowing developers to define values for these behaviors at a time which makes sense to them. E.g. application bootstrap, after passing configuration, environment variables etc. The behavior class constructors would be modified, accepting and defaulting to a null value. When not specified getListenerArgs would use a value from the <Identifier>Defaults class.

Just an idea, open to others.

final class SnowflakeDiscordDefaults
{
    private static int $workerId = 0;
    private static int $processId = 0;

    public static function getWorkerId(): int
    {
        return self::$workerId;
    }

    public static function setWorkerId(int $workerId): void
    {
        self::$workerId = $workerId;
    }

    public static function getProcessId(): int
    {
        return self::$processId;
    }

    public static function setProcessId(int $processId): void
    {
        self::$processId = $processId;
    }
}

final class SnowflakeDiscord extends BaseSnowflake
{
    public function __construct(
        string $field = 'snowflake',
        ?string $column = null,
        private ?int $workerId = null,
        private ?int $processId = null,
        bool $nullable = false,
    ) {
    }

    protected function getListenerArgs(): array
    {
        return [
            'field' => $this->field,
            'workerId' => $this->workerId === null ? SnowflakeDiscordDefaults::getWorkerId() : $this->workerId,
            'processId' => $this->processId === null ? SnowflakeDiscordDefaults::getProcessId() : $this->processId,
            'nullable' => $this->nullable,
        ];
    }
}

Copy link
Contributor Author

@puzzledpolymath puzzledpolymath Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented similar to above, however defaults are considered within __construct instead of getListenerArgs. Done for all relevant identifiers. @roxblnfk Please review/resolve when you get a moment keen to 🚢 and wrap up an initial implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure why there's a delay in merging? If something additional or changes are needed, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:code review The pull request needs review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants