mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
27 lines
792 B
JavaScript
27 lines
792 B
JavaScript
exports.seed = (knex) => {
|
|
// Deletes ALL existing entries
|
|
return knex('subscription_plan_subscriptions')
|
|
.then(async () => {
|
|
const tenants = await knex('tenants');
|
|
|
|
for (const tenant of tenants) {
|
|
const existingSubscription = await knex('subscription_plan_subscriptions')
|
|
.where('tenantId', tenant.id)
|
|
.first();
|
|
|
|
if (!existingSubscription) {
|
|
const freePlan = await knex('subscription_plans').where('slug', 'free').first();
|
|
|
|
await knex('subscription_plan_subscriptions').insert({
|
|
tenantId: tenant.id,
|
|
planId: freePlan.id,
|
|
slug: 'main',
|
|
startsAt: knex.fn.now(),
|
|
endsAt: null,
|
|
createdAt: knex.fn.now(),
|
|
});
|
|
}
|
|
}
|
|
});
|
|
};
|