@@ -21,6 +21,7 @@ import { constants } from '../core/index.mjs'
21
21
import { BaseCommand } from './base.mjs'
22
22
import * as flags from './flags.mjs'
23
23
import * as prompts from './prompts.mjs'
24
+ import { getFileContents , getEnvValue } from '../core/helpers.mjs'
24
25
25
26
export class MirrorNodeCommand extends BaseCommand {
26
27
constructor ( opts ) {
@@ -206,6 +207,56 @@ export class MirrorNodeCommand extends BaseCommand {
206
207
rendererOptions : constants . LISTR_DEFAULT_RENDERER_OPTION
207
208
} )
208
209
}
210
+ } ,
211
+ {
212
+ title : 'Seed DB data' ,
213
+ task : async ( ctx , parentTask ) => {
214
+ const subTasks = [
215
+ {
216
+ title : 'Insert data in public.file_data' ,
217
+ task : async ( ctx , _ ) => {
218
+ const namespace = self . configManager . getFlag ( flags . namespace )
219
+
220
+ const feesFileIdNum = 111
221
+ const exchangeRatesFileIdNum = 112
222
+ const timestamp = Date . now ( )
223
+
224
+ const fees = await getFileContents ( this . accountManager , namespace , feesFileIdNum )
225
+ const exchangeRates = await getFileContents ( this . accountManager , namespace , exchangeRatesFileIdNum )
226
+
227
+ const importFeesQuery = `INSERT INTO public.file_data(file_data, consensus_timestamp, entity_id, transaction_type) VALUES (decode('${ fees } ', 'hex'), ${ timestamp + '000000' } , ${ feesFileIdNum } , 17);`
228
+ const importExchangeRatesQuery = `INSERT INTO public.file_data(file_data, consensus_timestamp, entity_id, transaction_type) VALUES (decode('${ exchangeRates } ', 'hex'), ${
229
+ timestamp + '000001'
230
+ } , ${ exchangeRatesFileIdNum } , 17);`
231
+ const sqlQuery = [ importFeesQuery , importExchangeRatesQuery ] . join ( '\n' )
232
+
233
+ const pods = await this . k8 . getPodsByLabel ( [ 'app.kubernetes.io/name=postgres' ] )
234
+ if ( pods . length === 0 ) {
235
+ throw new FullstackTestingError ( 'postgres pod not found' )
236
+ }
237
+ const postgresPodName = pods [ 0 ] . metadata . name
238
+ const postgresContainerName = 'postgresql'
239
+ const mirrorEnvVars = await self . k8 . execContainer ( postgresPodName , postgresContainerName , '/bin/bash -c printenv' )
240
+ const mirrorEnvVarsArray = mirrorEnvVars . split ( '\n' )
241
+ const HEDERA_MIRROR_IMPORTER_DB_OWNER = getEnvValue ( mirrorEnvVarsArray , 'HEDERA_MIRROR_IMPORTER_DB_OWNER' )
242
+ const HEDERA_MIRROR_IMPORTER_DB_OWNERPASSWORD = getEnvValue ( mirrorEnvVarsArray , 'HEDERA_MIRROR_IMPORTER_DB_OWNERPASSWORD' )
243
+ const HEDERA_MIRROR_IMPORTER_DB_NAME = getEnvValue ( mirrorEnvVarsArray , 'HEDERA_MIRROR_IMPORTER_DB_NAME' )
244
+
245
+ await self . k8 . execContainer ( postgresPodName , postgresContainerName , [
246
+ 'psql' ,
247
+ `postgresql://${ HEDERA_MIRROR_IMPORTER_DB_OWNER } :${ HEDERA_MIRROR_IMPORTER_DB_OWNERPASSWORD } @localhost:5432/${ HEDERA_MIRROR_IMPORTER_DB_NAME } ` ,
248
+ '-c' ,
249
+ sqlQuery
250
+ ] )
251
+ }
252
+ }
253
+ ]
254
+
255
+ return parentTask . newListr ( subTasks , {
256
+ concurrent : false ,
257
+ rendererOptions : constants . LISTR_DEFAULT_RENDERER_OPTION
258
+ } )
259
+ }
209
260
}
210
261
] , {
211
262
concurrent : false ,
0 commit comments