- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 739
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat: Feature lifecycle sql store (#6790)
- v6.6.0
- v6.5.3
- v6.5.2
- v6.5.1
- v6.5.0
- v6.4.1
- v6.4.0
- v6.3.0
- v6.2.4
- v6.2.3
- v6.2.2
- v6.2.1
- v6.2.0
- v6.1.12
- v6.1.11
- v6.1.10
- v6.1.9
- v6.1.8
- v6.1.7
- v6.1.6
- v6.1.5
- v6.1.4
- v6.1.3
- v6.1.2
- v6.1.0
- v6.0.7
- v6.0.6
- v6.0.5
- v6.0.4
- v6.0.3
- v6.0.2
- v6.0.1
- v6.0.0
- v5.12.8
- v5.12.7
- v5.12.6
- v5.12.5
- v5.12.4
- v5.12.3
- v5.12.2
- v5.12.1
- v5.12.0
Showing
8 changed files
with
171 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/lib/features/feature-lifecycle/feature-lifecycle-store.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import type { | ||
FeatureLifecycleStage, | ||
IFeatureLifecycleStore, | ||
FeatureLifecycleView, | ||
StageName, | ||
} from './feature-lifecycle-store-type'; | ||
import type { Db } from '../../db/db'; | ||
|
||
type DBType = { | ||
feature: string; | ||
stage: StageName; | ||
created_at: Date; | ||
}; | ||
|
||
export class FeatureLifecycleStore implements IFeatureLifecycleStore { | ||
private db: Db; | ||
|
||
constructor(db: Db) { | ||
this.db = db; | ||
} | ||
|
||
async insert(featureLifecycleStage: FeatureLifecycleStage): Promise<void> { | ||
await this.db('feature_lifecycles') | ||
.insert({ | ||
feature: featureLifecycleStage.feature, | ||
stage: featureLifecycleStage.stage, | ||
}) | ||
.returning('*') | ||
.onConflict(['feature', 'stage']) | ||
.ignore(); | ||
} | ||
|
||
async get(feature: string): Promise<FeatureLifecycleView> { | ||
const results = await this.db('feature_lifecycles') | ||
.where({ feature }) | ||
.orderBy('created_at', 'asc'); | ||
|
||
return results.map(({ stage, created_at }: DBType) => ({ | ||
stage, | ||
enteredStageAt: created_at, | ||
})); | ||
} | ||
|
||
async stageExists(stage: FeatureLifecycleStage): Promise<boolean> { | ||
const result = await this.db.raw( | ||
`SELECT EXISTS(SELECT 1 FROM feature_lifecycles WHERE stage = ? and feature = ?) AS present`, | ||
[stage.stage, stage.feature], | ||
); | ||
const { present } = result.rows[0]; | ||
return present; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
exports.up = function(db, cb) { | ||
db.runSql( | ||
` | ||
CREATE TABLE IF NOT EXISTS feature_lifecycles ( | ||
feature VARCHAR(255) NOT NULL REFERENCES features(name) ON DELETE CASCADE, | ||
stage VARCHAR(255) NULL, | ||
created_at TIMESTAMP WITH TIME ZONE default now(), | ||
PRIMARY KEY (feature, stage) | ||
);`, | ||
cb, | ||
); | ||
}; | ||
|
||
exports.down = function(db, cb) { | ||
db.runSql('DROP TABLE IF EXISTS feature_lifecycles;', cb); | ||
}; |