Skip to content
Snippets Groups Projects
Commit 7deaa36d authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

feat: add migration

parent 9a5a4a3c
No related branches found
No related tags found
1 merge request!495Feat/us605 fluid price
...@@ -144,6 +144,11 @@ ...@@ -144,6 +144,11 @@
"type": "node", "type": "node",
"file": "services/aggregatorUsageEvents/ecolyo.js", "file": "services/aggregatorUsageEvents/ecolyo.js",
"trigger": "@cron 0 1 * * *" "trigger": "@cron 0 1 * * *"
},
"aggregatorUsageEvents": {
"type": "node",
"file": "services/fluidsPrices/ecolyo.js",
"trigger": "@cron 0 1 * * *"
} }
}, },
"permissions": { "permissions": {
......
...@@ -88,5 +88,347 @@ ...@@ -88,5 +88,347 @@
"price": 0.0919, "price": 0.0919,
"startDate": "2017-01-01T00:00:00.000Z", "startDate": "2017-01-01T00:00:00.000Z",
"endDate": "2017-01-31T23:59:59.000Z" "endDate": "2017-01-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0915,
"startDate": "2017-02-01T00:00:00.000Z",
"endDate": "2017-02-28T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0932,
"startDate": "2017-03-01T00:00:00.000Z",
"endDate": "2017-03-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0927,
"startDate": "2017-04-01T00:00:00.000Z",
"endDate": "2017-04-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0906,
"startDate": "2017-05-01T00:00:00.000Z",
"endDate": "2017-05-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0906,
"startDate": "2017-06-01T00:00:00.000Z",
"endDate": "2017-06-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0788,
"startDate": "2017-07-01T00:00:00.000Z",
"endDate": "2017-07-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0783,
"startDate": "2017-08-01T00:00:00.000Z",
"endDate": "2017-08-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0783,
"startDate": "2017-09-01T00:00:00.000Z",
"endDate": "2017-09-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0791,
"startDate": "2017-10-01T00:00:00.000Z",
"endDate": "2017-10-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0806,
"startDate": "2017-11-01T00:00:00.000Z",
"endDate": "2017-11-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0812,
"startDate": "2017-12-01T00:00:00.000Z",
"endDate": "2017-12-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0857,
"startDate": "2018-01-01T00:00:00.000Z",
"endDate": "2018-01-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0866,
"startDate": "2018-02-01T00:00:00.000Z",
"endDate": "2018-02-28T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0847,
"startDate": "2018-03-01T00:00:00.000Z",
"endDate": "2018-03-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0839,
"startDate": "2018-04-01T00:00:00.000Z",
"endDate": "2018-04-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0842,
"startDate": "2018-05-01T00:00:00.000Z",
"endDate": "2018-05-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0855,
"startDate": "2018-06-01T00:00:00.000Z",
"endDate": "2018-06-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0959,
"startDate": "2018-07-01T00:00:00.000Z",
"endDate": "2018-07-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0961,
"startDate": "2018-08-01T00:00:00.000Z",
"endDate": "2018-08-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0967,
"startDate": "2018-09-01T00:00:00.000Z",
"endDate": "2018-09-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0989,
"startDate": "2018-10-01T00:00:00.000Z",
"endDate": "2018-10-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.1031,
"startDate": "2018-11-01T00:00:00.000Z",
"endDate": "2018-11-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.1013,
"startDate": "2018-12-01T00:00:00.000Z",
"endDate": "2018-12-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0999,
"startDate": "2019-01-01T00:00:00.000Z",
"endDate": "2019-01-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0993,
"startDate": "2019-02-01T00:00:00.000Z",
"endDate": "2019-02-28T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0993,
"startDate": "2019-03-01T00:00:00.000Z",
"endDate": "2019-03-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0977,
"startDate": "2019-04-01T00:00:00.000Z",
"endDate": "2019-04-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0973,
"startDate": "2019-05-01T00:00:00.000Z",
"endDate": "2019-05-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0969,
"startDate": "2019-06-01T00:00:00.000Z",
"endDate": "2019-06-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0795,
"startDate": "2019-07-01T00:00:00.000Z",
"endDate": "2019-07-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0791,
"startDate": "2019-08-01T00:00:00.000Z",
"endDate": "2019-08-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0785,
"startDate": "2019-09-01T00:00:00.000Z",
"endDate": "2019-09-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.077,
"startDate": "2019-10-01T00:00:00.000Z",
"endDate": "2019-10-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0789,
"startDate": "2019-11-01T00:00:00.000Z",
"endDate": "2019-11-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0793,
"startDate": "2019-12-01T00:00:00.000Z",
"endDate": "2019-12-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0787,
"startDate": "2020-01-01T00:00:00.000Z",
"endDate": "2020-01-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0765,
"startDate": "2020-02-01T00:00:00.000Z",
"endDate": "2020-02-29T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0736,
"startDate": "2020-03-01T00:00:00.000Z",
"endDate": "2020-03-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.071,
"startDate": "2020-04-01T00:00:00.000Z",
"endDate": "2020-04-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0703,
"startDate": "2020-05-01T00:00:00.000Z",
"endDate": "2020-05-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0687,
"startDate": "2020-06-01T00:00:00.000Z",
"endDate": "2020-06-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0698,
"startDate": "2020-07-01T00:00:00.000Z",
"endDate": "2020-07-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0705,
"startDate": "2020-08-01T00:00:00.000Z",
"endDate": "2020-08-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0709,
"startDate": "2020-09-01T00:00:00.000Z",
"endDate": "2020-09-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0735,
"startDate": "2020-10-01T00:00:00.000Z",
"endDate": "2020-10-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0745,
"startDate": "2020-11-01T00:00:00.000Z",
"endDate": "2020-11-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0759,
"startDate": "2020-12-01T00:00:00.000Z",
"endDate": "2020-12-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.076,
"startDate": "2021-01-01T00:00:00.000Z",
"endDate": "2021-01-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0782,
"startDate": "2021-02-01T00:00:00.000Z",
"endDate": "2021-02-28T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0818,
"startDate": "2021-03-01T00:00:00.000Z",
"endDate": "2021-03-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.079,
"startDate": "2021-04-01T00:00:00.000Z",
"endDate": "2021-04-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0797,
"startDate": "2021-05-01T00:00:00.000Z",
"endDate": "2021-05-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0826,
"startDate": "2021-06-01T00:00:00.000Z",
"endDate": "2021-06-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0895,
"startDate": "2021-07-01T00:00:00.000Z",
"endDate": "2021-07-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0934,
"startDate": "2021-08-01T00:00:00.000Z",
"endDate": "2021-08-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.1002,
"startDate": "2021-09-01T00:00:00.000Z",
"endDate": "2021-09-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.1121,
"startDate": "2021-10-01T00:00:00.000Z",
"endDate": null
} }
] ]
...@@ -242,6 +242,7 @@ export const migrations: Migration[] = [ ...@@ -242,6 +242,7 @@ export const migrations: Migration[] = [
description: 'Init new doctype fluidPrices', description: 'Init new doctype fluidPrices',
releaseNotes: null, releaseNotes: null,
docTypes: FLUIDPRICES_DOCTYPE, docTypes: FLUIDPRICES_DOCTYPE,
isCreate: true,
run: async (_client: Client, docs: any[]): Promise<any> => { run: async (_client: Client, docs: any[]): Promise<any> => {
for (const fluidPrice of fluidsPricesData) { for (const fluidPrice of fluidsPricesData) {
await _client.create(FLUIDPRICES_DOCTYPE, fluidPrice) await _client.create(FLUIDPRICES_DOCTYPE, fluidPrice)
......
...@@ -152,6 +152,11 @@ export async function migrate( ...@@ -152,6 +152,11 @@ export async function migrate(
result = migrationNoop() result = migrationNoop()
} }
// Handle new doctype creation
if (migration.isCreate) {
await migration.run(_client, docToUpdate)
}
switch (result.type) { switch (result.type) {
case MIGRATION_RESULT_NOOP: case MIGRATION_RESULT_NOOP:
await updateSchemaVersion(_client, migration.targetSchemaVersion) await updateSchemaVersion(_client, migration.targetSchemaVersion)
......
...@@ -27,6 +27,7 @@ export type Migration = { ...@@ -27,6 +27,7 @@ export type Migration = {
description: string description: string
releaseNotes: Notes | null releaseNotes: Notes | null
docTypes: string docTypes: string
isCreate?: boolean
queryOptions?: MigrationQueryOptions queryOptions?: MigrationQueryOptions
appVersion: string appVersion: string
run: (_client: Client, docs: any[]) => Promise<any[]> run: (_client: Client, docs: any[]) => Promise<any[]>
......
import FluidPricesService from './fluidConfig.service'
describe('FluidPrices service', () => {
const fluidPricesService = new FluidPricesService()
describe('getFluidConfig', () => {
it('should get fluid config', () => {
const result = fluidPricesService.getFluidConfig()
expect(result).toBeDefined()
})
})
})
import { Q, Client, QueryDefinition, QueryResult } from 'cozy-client'
import { FLUIDPRICES_DOCTYPE } from 'doctypes'
import { FluidPrice } from 'models'
export default class FluidPricesService {
private readonly _client: Client
constructor(_client: Client) {
this._client = _client
}
public async getAllPrices(): Promise<FluidPrice[]> {
const query: QueryDefinition = Q(FLUIDPRICES_DOCTYPE)
const {
data: fluidsPrices,
}: QueryResult<FluidPrice[]> = await this._client.query(query)
return fluidsPrices
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment