@tisuchi
yes i saw that but at the on of the article he states that:
_Let’s say that the subscription with id 2 that we just upgraded to is up for renewal.
What we then do is create a new invoice with an invoice line representing the plan for the next period. Then we create a new subscription row, with value starts_at being equal to the ends_at value of the current subscription row, plus 1 milisecond so that they don’t overlap.
If the customer has downgraded their plan, we simply bill for the less expensive plan (in the column downgraded_to_plan_id) and create a subscription row with that plan instead of the previous plan.
Once a subscription row has been renewed, we run the following update query:_
UPDATE subscriptions SET
renewed_at = CURRENT_TIMESTAMP,
renewed_subscription_id = 2 -- Reference to the new subscription row we just create
WHERE customer_id = 1
AND CURRENT_TIMESTAMP BETWEEN starts_at AND ends_at
AND deleted_at IS NULL AND status = 'active';
here we created a new subscription renewal record but seemingly its not active. so here wen will we set the status of the old subscription as renewed and the new subscription as active?... if we had renewd the very day of subscription end date it was going to be easy coz i would create a new subscription and set the status as active then start date is now end date is + plan interval, then old subscription status is renewed.