Skip to content

Add Configurable PostgreSQL Storage Schema (Table and Column Names) for Backwards Compatibility #9

@warengonzaga

Description

@warengonzaga

Overview

Add configurable PostgreSQL table and column names to Nuvex, enabling backwards compatibility with existing applications (such as the Telegram and Discord bots) and smoother migrations to the new standard. Default names should be strongly branded as nuvex_*.

Related PR: #6


Problem

Nuvex currently uses hardcoded table/column names (e. g., key and value), which may not match existing production databases for Telegram/Discord bot users. This blocks smooth migration and prevents seamless adoption.


Proposal

  1. Default Schema (for new apps):

    • Table: nuvex_storage
    • Key Column: nuvex_key
    • Data Column: nuvex_data
    CREATE TABLE nuvex_storage (
      id SERIAL PRIMARY KEY,
      nuvex_key VARCHAR(255) UNIQUE NOT NULL,
      nuvex_data JSONB,
      expires_at TIMESTAMP,
      created_at TIMESTAMP DEFAULT NOW(),
      updated_at TIMESTAMP DEFAULT NOW()
    );
  2. Configurable for Existing Apps:

    • Example for a bot using storage_cache.key/storage_cache.value:
      const storage = new Nuvex({
        postgres:  {
          // ...
          schema: {
            tableName: 'storage_cache',
            columns: { key: 'key', value: 'value' }
          }
        }
      });
    • Example for a bot using storage_cache.cache_key/storage_cache.data:
      const storage = new Nuvex({
        postgres: {
          // ...
          schema: {
            tableName: 'storage_cache',
            columns:  { key: 'cache_key', value: 'data' }
          }
        }
      });

Implementation Tasks

  • Add PostgresSchemaConfig type to src/types/index.ts
  • Update PostgresConfig to accept schema?: PostgresSchemaConfig
  • Update PostgresStorage layer to use dynamic table/column names everywhere (get, set, delete, exists, clear)
  • Default values:
    • Table: nuvex_storage
    • Key Column: nuvex_key
    • Data Column: nuvex_data
  • Update/create database utility for initializing the table structure with correct names
  • Ensure all core and relevant existing/future tests pass for default and custom schemas
  • Add documentation/examples for schema configuration in the Nuvex README

Acceptance Criteria


Reference

App Table Key Column Data Column
Nuvex nuvex_storage nuvex_key nuvex_data
Telegram Bot storage_cache key value
Discord Bot storage_cache cache_key data

Reference: Discussion with @warengonzaga and PR #6

Metadata

Metadata

Labels

libraryLibrary implementation and core features (Issues/PRs)maintainerMaintainer expertise required (Issues/PRs)

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions