ensureSchema method

Future<void> ensureSchema()

Implementation

Future<void> ensureSchema() async {
  final DVRecordAdapter records = _records;
  await records.ensure(const DVRecordShape(
    collection: logTable,
    fields: _logFields,
  ));
  await records.ensure(const DVRecordShape(
    collection: stateTable,
    fields: <String, DVFieldType>{
      'id': DVFieldType.text,
      'allocated_through': DVFieldType.integer,
      'published_through': DVFieldType.integer,
      'pruned_through': DVFieldType.integer,
      'lease_until': DVFieldType.text,
    },
  ));
  await records.ensure(const DVRecordShape(
    collection: schemaTable,
    fields: <String, DVFieldType>{
      'model': DVFieldType.text,
      'columns': DVFieldType.text,
    },
  ));
  await records.ensure(const DVRecordShape(
    collection: checkpointTable,
    fields: <String, DVFieldType>{
      'consumer': DVFieldType.text,
      'change_seq': DVFieldType.integer,
      'updated_at': DVFieldType.text,
    },
  ));
  await records.ensure(const DVRecordShape(
    collection: backfillTable,
    fields: <String, DVFieldType>{
      'consumer': DVFieldType.text,
      'model': DVFieldType.text,
      'through_seq': DVFieldType.integer,
      'after_key': DVFieldType.text,
      'rows_done': DVFieldType.integer,
      'done': DVFieldType.integer,
    },
  ));
  final List<Map<String, Object?>> state = await records.find(
    stateTable,
    where: DVFilter.equals('id', _stateId),
    fields: const <String>['id'],
  );
  if (state.isEmpty) {
    await records.insert(stateTable, <String, Object?>{
      'id': _stateId,
      'allocated_through': 0,
      'published_through': 0,
      'pruned_through': 0,
      'lease_until': _stamp(DateTime.utc(1970)),
    });
  }
  _ready ??= Future<void>.value();
}