drift icon indicating copy to clipboard operation
drift copied to clipboard

Steps Migrations - error types Postges DateTime

Open bombicod opened this issue 5 months ago • 2 comments

When run - dart run drift_dev make-migrations was created file .steps.dart but linter check error, please help how fix this error?

Image
i1.GeneratedColumn<int> _column_0(String aliasedName) =>
    i1.GeneratedColumn<int>('id', aliasedName, false,
        hasAutoIncrement: true, type: i1.DriftSqlType.int);

i1.GeneratedColumn<double> _column_1(String aliasedName) =>
    i1.GeneratedColumn<double>('created_at', aliasedName, true,
        type: i1.DriftSqlType.double, defaultValue: now());

My fields

Image

bombicod avatar Jun 18 '25 10:06 bombicod

Could you post the linter errror or the complete tables so that I can reproduce this? Thanks!

simolus3 avatar Jun 18 '25 11:06 simolus3

For example 2 models with mixin TableMixin The function 'now' isn't defined. (undefined_function at /database.steps.dart:208) if add import 'package:drift_postgres/drift_postgres.dart';

Image
class LinkDocuments extends Table with TableMixin {
  IntColumn get userId => integer().references(Users, #id)();
}
class Users extends Table with TableMixin {
  TextColumn get name => text()();
}
mixin TableMixin on Table {
  late final IntColumn id = integer().autoIncrement()();

  late final TimestampColumn createdAt =
      customType(PgTypes.timestampWithTimezone).nullable().withDefault(now())();

  late final TimestampColumn updatedAt =
      customType(PgTypes.timestampWithTimezone).nullable().withDefault(now())();

  late final TimestampColumn deletedAt =
      customType(PgTypes.timestampWithTimezone).nullable().withDefault(now())();

}

The tests have errors too

Image

bombicod avatar Jun 18 '25 11:06 bombicod