Skip to content

Commit 91f9df4

Browse files
committed
multiple unleash and plans error
Signed-off-by: RAWx18 <rawx18.dev@gmail.com>
1 parent 2590714 commit 91f9df4

File tree

44 files changed

+1902
-902
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1902
-902
lines changed

backend/pnpm-workspace.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
onlyBuiltDependencies:
2+
- '@cubejs-backend/cubestore'
3+
- '@cubejs-backend/native'
4+
- '@gitmesh/cubejs'
5+
- '@opentelemetry/sdk-node'
6+
- aws-sdk
7+
- bcrypt
8+
- bufferutil
9+
- core-js
10+
- dtrace-provider
11+
- es5-ext
12+
- protobufjs
13+
- utf-8-validate
14+
- yarn
15+
- zlib-sync

backend/src/api/plan/stripe/checkout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default async (req, res) => {
1919
}
2020

2121
if (
22-
currentTenant.plan !== Plans.values.essential &&
22+
currentTenant.plan !== Plans.values.pro &&
2323
currentTenant.planStatus !== 'cancel_at_period_end' &&
2424
currentTenant.planUserId !== currentUser.id
2525
) {

backend/src/api/plan/stripe/portal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default async (req, res) => {
1919
}
2020

2121
if (
22-
currentTenant.plan !== Plans.values.essential &&
22+
currentTenant.plan !== Plans.values.pro &&
2323
currentTenant.planStatus !== 'cancel_at_period_end' &&
2424
currentTenant.planUserId !== currentUser.id
2525
) {

backend/src/bin/jobs/downgradeExpiredPlans.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ const job: GitmeshJob = {
2121

2222
for (const tenant of expiredTrialTenants[0]) {
2323
await dbOptions.database.tenant.update(
24-
{ isTrialPlan: false, trialEndsAt: null, plan: Plans.values.essential },
24+
{ isTrialPlan: false, trialEndsAt: null, plan: Plans.values.pro },
2525
{ returning: true, raw: true, where: { id: tenant.id } },
2626
)
2727
}
2828

2929
log.info('Downgrading expired non-trial plans')
3030
const expiredNonTrialTenants = await dbOptions.database.sequelize.query(
3131
`select t.id, t.name from tenants t
32-
where (t.plan = ${Plans.values.growth} or t.plan = ${Plans.values.signals} or t.plan = ${Plans.values.scale}) and t."planSubscriptionEndsAt" is not null and t."planSubscriptionEndsAt" + interval '3 days' < now()`,
32+
where t.plan = '${Plans.values.teamsPlus}' and t."planSubscriptionEndsAt" is not null and t."planSubscriptionEndsAt" + interval '3 days' < now()`,
3333
)
3434

3535
for (const tenant of expiredNonTrialTenants[0]) {
3636
await dbOptions.database.tenant.update(
37-
{ plan: Plans.values.essential },
37+
{ plan: Plans.values.pro },
3838
{ returning: true, raw: true, where: { id: tenant.id } },
3939
)
4040
}

backend/src/bin/scripts/change-tenant-plan.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const options = [
2222
name: 'plan',
2323
alias: 'p',
2424
type: String,
25-
description: `Plan that will be applied to the tenant. Accepted values are 'Growth' and 'Essential'.`,
25+
description: `Plan that will be applied to the tenant. Accepted values are 'Pro', 'Teams+', and 'Enterprise'.`,
2626
},
2727
{
2828
name: 'trialEndsAt',
@@ -59,7 +59,7 @@ const parameters = commandLineArgs(options)
5959

6060
if (parameters.help || !parameters.tenant || !parameters.plan) {
6161
console.log(usage)
62-
} else if (parameters.plan !== 'Growth' && parameters.plan !== 'Essential') {
62+
} else if (parameters.plan !== 'Pro' && parameters.plan !== 'Teams+' && parameters.plan !== 'Enterprise') {
6363
console.log(usage)
6464
console.log(`Invalid plan ${parameters.plan}`)
6565
} else {

backend/src/bin/scripts/unleash-init.ts

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ const constaintConfiguration = {
1515
[FeatureFlag.AUTOMATIONS]: [
1616
[
1717
{
18-
values: [Plans.values.scale],
18+
values: [Plans.values.pro],
1919
inverted: false,
2020
operator: 'IN',
2121
contextName: 'plan',
2222
caseInsensitive: false,
2323
},
2424
{
25-
value: PLAN_LIMITS[Plans.values.scale][FeatureFlag.AUTOMATIONS].toString(),
25+
value: PLAN_LIMITS[Plans.values.pro][FeatureFlag.AUTOMATIONS].toString(),
2626
values: [],
2727
inverted: false,
2828
operator: 'NUM_LT',
@@ -32,14 +32,14 @@ const constaintConfiguration = {
3232
],
3333
[
3434
{
35-
values: [Plans.values.growth],
35+
values: [Plans.values.teamsPlus],
3636
inverted: false,
3737
operator: 'IN',
3838
contextName: 'plan',
3939
caseInsensitive: false,
4040
},
4141
{
42-
value: PLAN_LIMITS[Plans.values.growth][FeatureFlag.AUTOMATIONS].toString(),
42+
value: PLAN_LIMITS[Plans.values.teamsPlus][FeatureFlag.AUTOMATIONS].toString(),
4343
values: [],
4444
inverted: false,
4545
operator: 'NUM_LT',
@@ -49,14 +49,14 @@ const constaintConfiguration = {
4949
],
5050
[
5151
{
52-
values: [Plans.values.essential],
52+
values: [Plans.values.enterprise],
5353
inverted: false,
5454
operator: 'IN',
5555
contextName: 'plan',
5656
caseInsensitive: false,
5757
},
5858
{
59-
value: PLAN_LIMITS[Plans.values.essential][FeatureFlag.AUTOMATIONS].toString(),
59+
value: PLAN_LIMITS[Plans.values.enterprise][FeatureFlag.AUTOMATIONS].toString(),
6060
values: [],
6161
inverted: false,
6262
operator: 'NUM_LT',
@@ -68,14 +68,14 @@ const constaintConfiguration = {
6868
[FeatureFlag.CSV_EXPORT]: [
6969
[
7070
{
71-
values: [Plans.values.scale],
71+
values: [Plans.values.pro],
7272
inverted: false,
7373
operator: 'IN',
7474
contextName: 'plan',
7575
caseInsensitive: false,
7676
},
7777
{
78-
value: PLAN_LIMITS[Plans.values.scale][FeatureFlag.CSV_EXPORT].toString(),
78+
value: PLAN_LIMITS[Plans.values.pro][FeatureFlag.CSV_EXPORT].toString(),
7979
values: [],
8080
inverted: false,
8181
operator: 'NUM_LT',
@@ -85,14 +85,14 @@ const constaintConfiguration = {
8585
],
8686
[
8787
{
88-
values: [Plans.values.growth],
88+
values: [Plans.values.teamsPlus],
8989
inverted: false,
9090
operator: 'IN',
9191
contextName: 'plan',
9292
caseInsensitive: false,
9393
},
9494
{
95-
value: PLAN_LIMITS[Plans.values.growth][FeatureFlag.CSV_EXPORT].toString(),
95+
value: PLAN_LIMITS[Plans.values.teamsPlus][FeatureFlag.CSV_EXPORT].toString(),
9696
values: [],
9797
inverted: false,
9898
operator: 'NUM_LT',
@@ -102,14 +102,14 @@ const constaintConfiguration = {
102102
],
103103
[
104104
{
105-
values: [Plans.values.essential],
105+
values: [Plans.values.enterprise],
106106
inverted: false,
107107
operator: 'IN',
108108
contextName: 'plan',
109109
caseInsensitive: false,
110110
},
111111
{
112-
value: PLAN_LIMITS[Plans.values.essential][FeatureFlag.CSV_EXPORT].toString(),
112+
value: PLAN_LIMITS[Plans.values.enterprise][FeatureFlag.CSV_EXPORT].toString(),
113113
values: [],
114114
inverted: false,
115115
operator: 'NUM_LT',
@@ -121,7 +121,7 @@ const constaintConfiguration = {
121121
[FeatureFlag.SIGNALS]: [
122122
[
123123
{
124-
values: [Plans.values.growth, Plans.values.signals, Plans.values.scale, Plans.values.enterprise],
124+
values: [Plans.values.pro, Plans.values.teamsPlus, Plans.values.enterprise],
125125
inverted: false,
126126
operator: 'IN',
127127
contextName: 'plan',
@@ -132,7 +132,7 @@ const constaintConfiguration = {
132132
[FeatureFlag.LINKEDIN]: [
133133
[
134134
{
135-
values: [Plans.values.growth, Plans.values.scale, Plans.values.enterprise],
135+
values: [Plans.values.pro, Plans.values.teamsPlus, Plans.values.enterprise],
136136
inverted: false,
137137
operator: 'IN',
138138
contextName: 'plan',
@@ -143,7 +143,7 @@ const constaintConfiguration = {
143143
[FeatureFlag.HUBSPOT]: [
144144
[
145145
{
146-
values: [Plans.values.scale, Plans.values.enterprise],
146+
values: [Plans.values.teamsPlus, Plans.values.enterprise],
147147
inverted: false,
148148
operator: 'IN',
149149
contextName: 'plan',
@@ -154,14 +154,14 @@ const constaintConfiguration = {
154154
[FeatureFlag.MEMBER_ENRICHMENT]: [
155155
[
156156
{
157-
values: [Plans.values.scale],
157+
values: [Plans.values.pro],
158158
inverted: false,
159159
operator: 'IN',
160160
contextName: 'plan',
161161
caseInsensitive: false,
162162
},
163163
{
164-
value: PLAN_LIMITS[Plans.values.scale][FeatureFlag.MEMBER_ENRICHMENT].toString(),
164+
value: PLAN_LIMITS[Plans.values.pro][FeatureFlag.MEMBER_ENRICHMENT].toString(),
165165
values: [],
166166
inverted: false,
167167
operator: 'NUM_LT',
@@ -171,14 +171,14 @@ const constaintConfiguration = {
171171
],
172172
[
173173
{
174-
values: [Plans.values.growth],
174+
values: [Plans.values.teamsPlus],
175175
inverted: false,
176176
operator: 'IN',
177177
contextName: 'plan',
178178
caseInsensitive: false,
179179
},
180180
{
181-
value: PLAN_LIMITS[Plans.values.growth][FeatureFlag.MEMBER_ENRICHMENT].toString(),
181+
value: PLAN_LIMITS[Plans.values.teamsPlus][FeatureFlag.MEMBER_ENRICHMENT].toString(),
182182
values: [],
183183
inverted: false,
184184
operator: 'NUM_LT',
@@ -190,14 +190,14 @@ const constaintConfiguration = {
190190
[FeatureFlag.ORGANIZATION_ENRICHMENT]: [
191191
[
192192
{
193-
values: [Plans.values.scale],
193+
values: [Plans.values.pro],
194194
inverted: false,
195195
operator: 'IN',
196196
contextName: 'plan',
197197
caseInsensitive: false,
198198
},
199199
{
200-
value: PLAN_LIMITS[Plans.values.scale][FeatureFlag.ORGANIZATION_ENRICHMENT].toString(),
200+
value: PLAN_LIMITS[Plans.values.pro][FeatureFlag.ORGANIZATION_ENRICHMENT].toString(),
201201
values: [],
202202
inverted: false,
203203
operator: 'NUM_LT',
@@ -207,14 +207,14 @@ const constaintConfiguration = {
207207
],
208208
[
209209
{
210-
values: [Plans.values.growth],
210+
values: [Plans.values.teamsPlus],
211211
inverted: false,
212212
operator: 'IN',
213213
contextName: 'plan',
214214
caseInsensitive: false,
215215
},
216216
{
217-
value: PLAN_LIMITS[Plans.values.growth][FeatureFlag.ORGANIZATION_ENRICHMENT].toString(),
217+
value: PLAN_LIMITS[Plans.values.teamsPlus][FeatureFlag.ORGANIZATION_ENRICHMENT].toString(),
218218
values: [],
219219
inverted: false,
220220
operator: 'NUM_LT',
@@ -230,11 +230,9 @@ const constaintConfiguration = {
230230
[
231231
{
232232
values: [
233-
Plans.values.scale,
234-
Plans.values.signals,
233+
Plans.values.pro,
234+
Plans.values.teamsPlus,
235235
Plans.values.enterprise,
236-
Plans.values.essential,
237-
Plans.values.growth,
238236
],
239237
inverted: false,
240238
operator: 'IN',
@@ -247,11 +245,9 @@ const constaintConfiguration = {
247245
[
248246
{
249247
values: [
250-
Plans.values.scale,
251-
Plans.values.signals,
248+
Plans.values.pro,
249+
Plans.values.teamsPlus,
252250
Plans.values.enterprise,
253-
Plans.values.essential,
254-
Plans.values.growth,
255251
],
256252
inverted: false,
257253
operator: 'IN',
@@ -265,11 +261,9 @@ const constaintConfiguration = {
265261
[
266262
{
267263
values: [
268-
Plans.values.scale,
269-
Plans.values.signals,
264+
Plans.values.pro,
265+
Plans.values.teamsPlus,
270266
Plans.values.enterprise,
271-
Plans.values.essential,
272-
Plans.values.growth,
273267
],
274268
inverted: false,
275269
operator: 'IN',
@@ -321,29 +315,36 @@ setImmediate(async () => {
321315

322316
async function createApiToken(token: string, name: string, type: string): Promise<void> {
323317
const results = await seq.query(
324-
'select * from api_tokens where secret = :token and type = :type and username = :name;',
318+
'select * from api_tokens where secret = :token;',
325319
{
326320
replacements: {
327321
token,
328-
name,
329-
type,
330322
},
331323
type: QueryTypes.SELECT,
332324
},
333325
)
334326
if (results.length === 0) {
335327
log.info(`${name} token not found - creating...`)
336-
await seq.query(
337-
`insert into api_tokens(secret, username, type, environment) values (:token, :name, :type, 'production')`,
338-
{
339-
replacements: {
340-
token,
341-
name,
342-
type,
328+
try {
329+
await seq.query(
330+
`insert into api_tokens(secret, username, type, environment) values (:token, :name, :type, 'production')`,
331+
{
332+
replacements: {
333+
token,
334+
name,
335+
type,
336+
},
337+
type: QueryTypes.INSERT,
343338
},
344-
type: QueryTypes.INSERT,
345-
},
346-
)
339+
)
340+
log.info(`${name} token created successfully!`)
341+
} catch (err) {
342+
if (err.name === 'SequelizeUniqueConstraintError') {
343+
log.info(`${name} token already exists (created by another process)`)
344+
} else {
345+
throw err
346+
}
347+
}
347348
} else {
348349
log.info(`${name} token found!`)
349350
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- Add new plan enum values for the enterprise edition restructure
2+
-- This migration adds 'Pro' and 'Teams+' to the tenant_plans_type enum
3+
-- while maintaining backwards compatibility with existing plans
4+
5+
-- Add 'Pro' enum value
6+
DO $$
7+
BEGIN
8+
IF NOT EXISTS (
9+
SELECT 1 FROM pg_enum
10+
WHERE enumlabel = 'Pro'
11+
AND enumtypid = (SELECT oid FROM pg_type WHERE typname = 'tenant_plans_type')
12+
) THEN
13+
ALTER TYPE tenant_plans_type ADD VALUE 'Pro';
14+
END IF;
15+
END $$;
16+
17+
-- Add 'Teams+' enum value
18+
DO $$
19+
BEGIN
20+
IF NOT EXISTS (
21+
SELECT 1 FROM pg_enum
22+
WHERE enumlabel = 'Teams+'
23+
AND enumtypid = (SELECT oid FROM pg_type WHERE typname = 'tenant_plans_type')
24+
) THEN
25+
ALTER TYPE tenant_plans_type ADD VALUE 'Teams+';
26+
END IF;
27+
END $$;

0 commit comments

Comments
 (0)