import { sql } from "drizzle-orm";
import { db, pool } from "./index";

async function main() {
  const result = await db.execute(sql`
    update membership_subscriptions
    set
      end_date = (coalesce(start_date, created_at) + interval '1 year'),
      renews_at = (coalesce(start_date, created_at) + interval '1 year'),
      updated_at = now()
    where status = 'ACTIVE'
      and coalesce(start_date, created_at) is not null
  `);
  console.log(result);
}

main()
  .catch((err) => {
    console.error(err);
    process.exitCode = 1;
  })
  .finally(async () => {
    await pool.end();
  });

