Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing archivedAt to featureSchema #1779

Merged
merged 23 commits into from Jul 1, 2022
Merged

Conversation

sellinjaanus
Copy link
Contributor

  1. Added archivedAt column to features
  2. Added database scripts that handle the population of new field based on events. If events are missing, the current date is set.
  3. Removed 2 unused methods on FeatureToggleStore, which are covered by FeatureToggleStore.getAll method
  4. Added test that checks that both columns will be sent to API, when archived features are queried.
  5. The old archived column will not be used anymore, but as discussed in daily standup, not yet deleted. Will be deleted in future, if everything goes smoothly.

@vercel
Copy link

vercel bot commented Jun 30, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated
unleash-docs ⬜️ Ignored (Inspect) Jun 30, 2022 at 4:08PM (UTC)

@sellinjaanus
Copy link
Contributor Author

@github-actions
Copy link

github-actions bot commented Jun 30, 2022

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 92.06% 5717/6210
🟢 Branches
81.05% (+1.5% 🔼)
881/1087
🟢 Functions 86.61% 1255/1449
🟢 Lines 91.99% 5585/6071
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / ensureStringValue.ts
100% 100% 100% 100%
🟢
... / isDefined.ts
100% 100% 100% 100%
🟢
... / map-values.ts
100% 100% 100% 100%
🟢 lib/util/env.ts 100% 100% 100% 100%
🟢
... / validateJsonString.ts
100% 100% 100% 100%
🟢 lib/util/semver.ts 92.86% 100% 100% 91.67%
🟢
... / addon-parameter-schema.ts
100% 100% 100% 100%
🟢
... / addon-schema.ts
100% 100% 100% 100%
🟢
... / addons-schema.ts
100% 100% 100% 100%
🟢
... / addon-type-schema.ts
100% 100% 100% 100%
🟢
... / tag-type-schema.ts
100% 100% 100% 100%
🟢
... / api-token-schema.ts
100% 100% 100% 100%
🟢
... / api-tokens-schema.ts
100% 100% 100% 100%
🟢
... / application-schema.ts
100% 100% 100% 100%
🟢
... / applications-schema.ts
100% 100% 100% 100%
🟢
... / bootstrap-ui-schema.ts
100% 100% 100% 100%
🟢
... / ui-config-schema.ts
100% 100% 100% 100%
🟢
... / version-schema.ts
100% 100% 100% 100%
🟢
... / user-schema.ts
100% 100% 100% 100%
🟢
... / permission-schema.ts
100% 100% 100% 100%
🟢
... / feature-type-schema.ts
100% 100% 100% 100%
🟢
... / context-field-schema.ts
100% 100% 100% 100%
🟢
... / legal-value-schema.ts
100% 100% 100% 100%
🟢
... / project-schema.ts
100% 100% 100% 100%
🟢
... / change-password-schema.ts
100% 100% 100% 100%
🟢
... / client-application-schema.ts
100% 100% 100% 100%
🟢
... / client-feature-schema.ts
100% 100% 100% 100%
🟢
... / client-variant-schema.ts
100% 100% 100% 100%
🟢
... / client-features-query-schema.ts
100% 100% 100% 100%
🟢
... / client-features-schema.ts
100% 100% 100% 100%
🟢
... / segment-schema.ts
100% 100% 100% 100%
🟢
... / environment-schema.ts
100% 100% 100% 100%
🟢
... / client-metrics-schema.ts
100% 100% 100% 100%
🟢
... / date-schema.ts
100% 100% 100% 100%
🟢
... / context-fields-schema.ts
100% 100% 100% 100%
🟢
... / create-api-token-schema.ts
100% 100% 100% 100%
🟢
... / create-feature-strategy-schema.ts
100% 100% 100% 100%
🟢
... / create-user-schema.ts
100% 100% 100% 100%
🟢
... / email-schema.ts
100% 100% 100% 100%
🟢
... / environments-schema.ts
100% 100% 100% 100%
🟢
... / event-schema.ts
100% 100% 100% 100%
🟢
... / events-schema.ts
100% 100% 100% 100%
🟢
... / export-parameters-schema.ts
100% 100% 100% 100%
🟢
... / feature-environment-metrics-schema.ts
100% 100% 100% 100%
🟢
... / feature-environment-schema.ts
100% 100% 100% 100%
🟢
... / feature-events-schema.ts
100% 100% 100% 100%
🟢
... / feature-metrics-schema.ts
100% 100% 100% 100%
🟢
... / feature-strategy-segment-schema.ts
100% 100% 100% 100%
🟢
... / feature-tag-schema.ts
100% 100% 100% 100%
🟢
... / feature-types-schema.ts
100% 100% 100% 100%
🟢
... / feature-usage-schema.ts
100% 100% 100% 100%
🟢
... / feature-variants-schema.ts
100% 100% 100% 100%
🟢
... / feedback-schema.ts
100% 100% 100% 100%
🟢
... / health-check-schema.ts
100% 100% 100% 100%
🟢
... / health-overview-schema.ts
100% 100% 100% 100%
🟢
... / health-report-schema.ts
100% 100% 100% 100%
🟢
... / id-schema.ts
100% 100% 100% 100%
🟢
... / login-schema.ts
100% 100% 100% 100%
🟢
... / me-schema.ts
100% 100% 100% 100%
🟢
... / name-schema.ts
100% 100% 100% 100%
🟢
... / omit-keys.ts
100% 100% 100% 100%
🟢
... / password-schema.ts
100% 100% 100% 100%
🟢
... / patches-schema.ts
100% 100% 100% 100%
🟢
... / patch-schema.ts
100% 100% 100% 100%
🟢
... / project-environment-schema.ts
100% 100% 100% 100%
🟢
... / projects-schema.ts
100% 100% 100% 100%
🟢
... / reset-password-schema.ts
100% 100% 100% 100%
🟢
... / role-schema.ts
100% 100% 100% 100%
🟢
... / sort-order-schema.ts
100% 100% 100% 100%
🟢
... / splash-schema.ts
100% 100% 100% 100%
🟢
... / state-schema.ts
100% 100% 100% 100%
🟢
... / strategies-schema.ts
100% 100% 100% 100%
🟢
... / tags-schema.ts
100% 100% 100% 100%
🟢
... / tag-types-schema.ts
100% 100% 100% 100%
🟢
... / tag-with-version-schema.ts
100% 100% 100% 100%
🟢
... / token-user-schema.ts
100% 100% 100% 100%
🟢
... / update-api-token-schema.ts
100% 100% 100% 100%
🟢
... / update-feature-schema.ts
100% 100% 100% 100%
🟢
... / update-feature-strategy-schema.ts
100% 100% 100% 100%
🟢
... / update-tag-type-schema.ts
100% 100% 100% 100%
🟢
... / update-user-schema.ts
100% 100% 100% 100%
🟢
... / upsert-context-field-schema.ts
100% 100% 100% 100%
🟢
... / upsert-strategy-schema.ts
100% 100% 100% 100%
🟢
... / users-schema.ts
100% 100% 100% 100%
🟢
... / users-search-schema.ts
100% 100% 100% 100%
🟢
... / validate-password-schema.ts
100% 100% 100% 100%
🟢
... / validate-tag-type-schema.ts
100% 100% 100% 100%
🟢
... / variants-schema.ts
100% 100% 100% 100%
🟢
... / standard-responses.ts
100% 100% 100% 100%
🟢
... / serialize-dates.ts
100% 100% 100% 100%
🟢
... / anonymise.ts
100% 100% 100% 100%
🟢
... / endpoint-descriptions.ts
100% 100% 100% 100%
🟢
... / bootstrap-ui.ts
100% 100% 100% 100%
🟢
... / api-token.ts
92.86% 60% 100% 92.68%
🟢
... / user-feedback.ts
100% 71.43% 100% 100%
🟢
... / user-splash.ts
100% 100% 100% 100%
🟢
... / environments.ts
100% 100% 100% 100%
🟢
... / validate.ts
100% 66.67% 100% 100%
🟢
... / client-spec-service.ts
100% 100% 100% 100%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / feature-strategy-store.ts
90.83% 79.31% 82.86% 91.45%
🟢
... / create-config.ts
96.69%
91.11% (+6.04% 🔼)
90% (-10% 🔻)
96.61%
🟡
... / access-service.ts
79.71% 93.1% 82% 78.63%
🟢 lib/routes/util.ts
84.85% (-3.03% 🔻)
73.68% (-5.26% 🔻)
100%
84.38% (-3.13% 🔻)
🟢
... / constraint-types.ts
93.33% (-3.44% 🔻)
83.33% (-16.67% 🔻)
85.71%
91.67% (-4.17% 🔻)
🟢
... / controller.ts
96.88% (-3.13% 🔻)
100%
93.33% (-6.67% 🔻)
96.77% (-3.23% 🔻)
🟢
... / user-admin.ts
90.8% (+3.9% 🔼)
66.67% (-13.33% 🔻)
76.92% (-6.41% 🔻)
91.86% (+4.96% 🔼)
🟢
... / features.ts
91.89% 100% 89.47% 91.89%
🟢
... / metrics.ts
88.89% (-2.02% 🔻)
33.33% 100%
88.89% (-2.02% 🔻)
🟢
... / user-service.ts
88.97% (-1.18% 🔻)
69.39% (-1.34% 🔻)
86.36%
89.55% (-1.22% 🔻)
🔴
... / password-undefined.ts
14.29% (-85.71% 🔻)
100%
0% (-100% 🔻)
14.29% (-85.71% 🔻)
🟡
... / user-splash-service.ts
69.23% (-2.2% 🔻)
0% 80%
69.23% (-2.2% 🔻)

Test suite run success

992 tests passing in 166 suites.

Report generated by 🧪jest coverage report action from eb24007

exports.up = function (db, callback) {
db.runSql(
`
ALTER TABLE features ADD archived_at date;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use TIMESTAMP WITH TIME ZONE instead of date?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would align better with rest of the schema.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const row = await this.db(TABLE)
.where({ name })
.update({ archived: true })
.update({ archived_at: now })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep setting archived as well, while we have both columns?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think so, because we dont want to be dependant on manually setting the column. We want the archived value to be calculated always from archived_dt, so if we eventually removed archived column, then we know that everything has been working fine based on just the date column.

Comment on lines 150 to 155
if (archived) {
queryBuilder.whereNotNull('archived_at');
} else {
queryBuilder.whereNull('archived_at');
}
return queryBuilder;
Copy link
Contributor

@olav olav Jun 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could perhaps line up the conditions:

return archived 
    ? queryBuilder.whereNotNull('archived_at') 
    : queryBuilder.whereNull('archived_at');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we can go with shortif.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -2,11 +2,10 @@
id: events
title: /api/admin/events
---

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would revert this file, unless there are any non-formatting changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -53,6 +54,7 @@ export interface FeatureToggleDTO {
export interface FeatureToggle extends FeatureToggleDTO {
project: string;
lastSeenAt?: Date;
variants?: IVariant[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like variants should already be here, from FeatureToggleDTO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

.expect(200)
.expect((res) => {
expect(res.body.features.length).toEqual(3);
expect(res.body.features[0].archivedAt).toBeTruthy();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could check all the features:

.expect((res) => {
    expect(res.body.features.length).toEqual(3);
    expect(res.body.features.every((f) => f.archived)).toEqual(true);
    expect(res.body.features.every((f) => f.archivedAt)).toEqual(true);
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was designing thinking in a mind that a test should usually test single functionality, but either is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to single test.

@sellinjaanus sellinjaanus requested a review from olav June 30, 2022 16:11
Copy link
Contributor

@andreas-unleash andreas-unleash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sellinjaanus sellinjaanus merged commit 04fb065 into main Jul 1, 2022
@sellinjaanus sellinjaanus deleted the feature_archive_date branch July 1, 2022 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants