Skip to content

Database Schema

All tables use the WordPress table prefix ($wpdb->prefix).

Tables

{prefix}renewal_discount_types

Stores the available discount types (one row per registered scheme).

Column Type Notes
id int(11) unsigned Primary key, auto-increment
type varchar(30) Unique scheme enum (e.g. fixed_amount)
enabled tinyint(1) 1 = active

{prefix}renewal_discount

One row per discount assigned to a subscription.

Column Type Notes
id int(11) unsigned Primary key, auto-increment
type_id int(11) unsigned FK → renewal_discount_types.id
subscription_id bigint(20) unsigned FK → wp_posts.ID (subscription)
order_id bigint(20) unsigned FK → wp_posts.ID; NULL until applied to a renewal order
created_by bigint(20) WordPress user ID
created_via varchar(50) Source identifier (e.g. rest, ajax, manual)
created_at datetime
updated_at datetime Auto-updated on row change

{prefix}renewal_discount_meta

Key/value metadata per discount record (managed by ORMModelWithMeta).

ER Diagram

erDiagram
    wp_posts {
        bigint ID PK
        varchar post_type
    }

    renewal_discount_types {
        int id PK
        varchar type
        tinyint enabled
    }

    renewal_discount {
        int id PK
        int type_id FK
        bigint subscription_id FK
        bigint order_id FK
        bigint created_by
        varchar created_via
        datetime created_at
        datetime updated_at
    }

    renewal_discount_meta {
        int id PK
        int discount_id FK
        varchar meta_key
        text meta_value
    }

    renewal_discount_types ||--o{ renewal_discount : "type_id"
    wp_posts ||--o{ renewal_discount : "subscription_id"
    wp_posts ||--o{ renewal_discount : "order_id"
    renewal_discount ||--o{ renewal_discount_meta : "discount_id"

Migrations

Migrations live in src/Migrations/Versions/ and are registered in Migrator::get_migrations().

Version Changes
1.0.0 Creates renewal_discount_types and renewal_discount tables; seeds fixed_amount type
1.1.0 Adds renewal_discount_meta table
1.2.0 HPOS compatibility updates

To add a new migration: create Migration_X_Y_Z.php implementing the Migration interface and append it to the array in Migrator::get_migrations().