Skip to content

Added support for table prefix#421

Open
argxh wants to merge 4 commits intohangfire-postgres:masterfrom
argxh:feature/add_prefix_table
Open

Added support for table prefix#421
argxh wants to merge 4 commits intohangfire-postgres:masterfrom
argxh:feature/add_prefix_table

Conversation

@argxh
Copy link

@argxh argxh commented Feb 9, 2026

Added support for table prefix

The feature was required for integration in a multi-database web service and aligns PostgreSQL behavior with other DB providers.

Table prefixing is applied after migrations execution, so it does not affect existing or future raw SQL migrations and remains fully backward compatible.

Whats new?

  • Added parameters UseTablePrefix and TablePrefixName in PostgreSqlStorageOptions
  • Added handlers in all the db operations
  • Added unit tests

How to use?

Both parameters have default values like false for UseTablePrefix and "hangfire"_ for TablePrefixName, so you can customize it or leave it default.

You can simply define them in your database configuration within your project:

services.AddHangfire(config =>
 {
     config.UsePostgreSqlStorage(options =>
     {
         options.UseNpgsqlConnection(connectionString);
     }, new PostgreSqlStorageOptions
     {
         QueuePollInterval = TimeSpan.FromSeconds(15),
         PrepareSchemaIfNecessary = true,
         DistributedLockTimeout = TimeSpan.FromMinutes(10),
         InvisibilityTimeout = TimeSpan.FromMinutes(30),
         UseTablePrefix = true,
         TablePrefixName = "prefix_here"
     });
     config.UseSimpleAssemblyNameTypeSerializer();
     config.UseRecommendedSerializerSettings();
     
 });

@azygis
Copy link
Collaborator

azygis commented Feb 10, 2026

I would prefer less verbosity - instead of two properties, use one, TablePrefix, default to nothing. At that point there's no need for a bunch of conditionals, simply format the string with $"{tablePrefix}{tableName}. You opt-in to this by simply setting one property for prefix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants