-- RDS_USER_RECENT_SUBSCRIPTION table for storing recent subscription data from RDS
-- This table is populated by the Glue job which dumps data from RDS to S3 
-- and then loads it into Snowflake
-- Clustered by partition date and hour for optimal query performance
CREATE TRANSIENT TABLE IF NOT EXISTS {user_recent_subscription_table_name} CLUSTER BY (p_date, p_hour) (
    -- Primary identifier
    ID VARCHAR(255),                                    -- Unique subscription identifier
    
    -- User and subscription details
    USER_ID NUMBER(38,0),                               -- User who made the subscription
    AMOUNT_PAID DECIMAL(10,2),                          -- Amount paid for subscription
    CURRENCY VARCHAR(8),                                -- Currency code (e.g., USD, EUR)
    PAYMENT_METHOD_TYPE VARCHAR(32),                    -- Type of payment method used
    
    -- Timestamps
    CREATED_AT TIMESTAMP_TZ(9),                         -- When the subscription was created
    UPDATED_AT TIMESTAMP_TZ(9),                         -- Last update timestamp
    
    -- Partitioning columns for optimization
    P_DATE DATE,                                        -- Partition date based on created_at
    P_HOUR NUMBER(38,0)                                 -- Partition hour (0-23) based on created_at
);

