prisma / prisma-test-utils

A collection of data model agnostic test utils.
112 stars 10 forks source link

Error: Unsupported ID type "DateTime" #35

Open divyenduz opened 4 years ago

divyenduz commented 4 years ago

Fails for Joomla table:

https://github.com/prisma/database-schema-examples/blob/master/mysql/joomla/schema.sql#L137-L156

CREATE TABLE `zfah5_banner_clients` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  `contact` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  `email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  `extrainfo` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `state` tinyint(3) NOT NULL DEFAULT '0',
  `checked_out` int(10) unsigned NOT NULL DEFAULT '0',
  `checked_out_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `metakey` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `own_prefix` tinyint(4) NOT NULL DEFAULT '0',
  `metakey_prefix` varchar(400) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  `purchase_type` tinyint(4) NOT NULL DEFAULT '-1',
  `track_clicks` tinyint(4) NOT NULL DEFAULT '-1',
  `track_impressions` tinyint(4) NOT NULL DEFAULT '-1',
  PRIMARY KEY (`id`),
  KEY `idx_own_prefix` (`own_prefix`),
  KEY `idx_metakey_prefix` (`metakey_prefix`(100))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Introspected model:

model zfah5_banner_clients {
  checked_out       Int      @default(0)
  checked_out_time  DateTime
  contact           String   @default("")
  email             String   @default("")
  extrainfo         String
  id                Int      @default(autoincrement()) @id
  metakey           String
  metakey_prefix    String   @default("")
  name              String   @default("")
  own_prefix        Int      @default(0)
  purchase_type     Int
  state             Int      @default(0)
  track_clicks      Int
  track_impressions Int

  @@index([metakey_prefix], name: "idx_metakey_prefix")
  @@index([own_prefix], name: "idx_own_prefix")
}

This is most likely a test-utils bug as it is not reproducible directly with client when using the same call.

All seed logs: https://github.com/prisma/introspection-engine-output/blob/test_utils/test-utils/results/mysql_public_test_utils_joomla_stderr.log#L703

/home/runner/work/introspection-engine-output/introspection-engine-output/clients/mysql_public_test_utils/joomla
===start client generation===
2020-03-11T12:12:59.473Z prisma-client {
  engineConfig: {
    cwd: '/home/runner/work/introspection-engine-output/introspection-engine-output/mysql_public_test_utils',
    debug: false,
    datamodelPath: '/home/runner/work/introspection-engine-output/introspection-engine-output/clients/mysql_public_test_utils/joomla/schema.prisma',
    prismaPath: undefined,
    datasources: [],
    generator: {
      name: 'client',
      provider: 'prisma-client-js',
      output: '/home/runner/work/introspection-engine-output/introspection-engine-output/clients/mysql_public_test_utils/joomla',
      binaryTargets: [],
      config: {}
    },
    showColors: false,
    logLevel: undefined,
    logQueries: undefined,
    env: {},
    flags: []
  }
}
===end client generation===
===start seed===
2020-03-11T12:12:59.589Z prisma-client Prisma Client call:
2020-03-11T12:12:59.590Z prisma-client prisma.zfah5_action_logs.create({
  data: {
    extension: 'ofosid',
    ip_address: 'daej',
    item_id: 405,
    log_date: new Date('2091-02-19T00:03:58.721Z'),
    message: 'gafgohrak',
    message_language_key: 'ro',
    user_id: -401
  }
})
2020-03-11T12:12:59.590Z prisma-client Generated request:
2020-03-11T12:12:59.590Z prisma-client mutation {
  createOnezfah5_action_logs(data: {
    extension: "ofosid"
    ip_address: "daej"
    item_id: 405
    log_date: "2091-02-19T00:03:58.721Z"
    message: "gafgohrak"
    message_language_key: "ro"
    user_id: -401
  }) {
    extension
    id
    ip_address
    item_id
    log_date
    message
    message_language_key
    user_id
  }
}

2020-03-11T12:12:59.593Z engine {
  PRISMA_DML_PATH: '/home/runner/work/introspection-engine-output/introspection-engine-output/clients/mysql_public_test_utils/joomla/schema.prisma',
  PORT: '43455',
  RUST_BACKTRACE: '1',
  RUST_LOG: 'info',
  OVERWRITE_DATASOURCES: '[]'
}
2020-03-11T12:12:59.594Z engine {
  cwd: '/home/runner/work/introspection-engine-output/introspection-engine-output/mysql_public_test_utils'
}
2020-03-11T12:12:59.596Z getos { version: 'OpenSSL 1.1.1d  10 Sep 2019\n' }
2020-03-11T12:12:59.596Z getos { ls: '' }
2020-03-11T12:12:59.598Z getos { platform: 'linux', libssl: '1.1.x' }
2020-03-11T12:12:59.598Z plusX Execution permissions of /home/runner/work/introspection-engine-output/introspection-engine-output/clients/mysql_public_test_utils/joomla/runtime/query-engine-debian-openssl-1.1.x are fine
2020-03-11T12:12:59.599Z engine { flags: [ '--enable-raw-queries' ] }
2020-03-11T12:12:59.616Z engine stderr Printing to stderr for debugging
2020-03-11T12:12:59.617Z engine stderr Listening on 127.0.0.1:43455
2020-03-11T12:12:59.629Z engine stdout {
  timestamp: 'Mar 11 12:12:59.628',
  level: 'INFO',
  target: 'quaint::pooled',
  fields: { message: 'Starting a mysql pool with 5 connections.' }
}
2020-03-11T12:12:59.642Z engine stdout {
  timestamp: 'Mar 11 12:12:59.642',
  level: 'INFO',
  target: 'prisma::server',
  fields: {
    message: 'Started http server on 127.0.0.1:43455',
    'log.target': 'prisma::server',
    'log.module_path': 'prisma::server',
    'log.file': 'query-engine/prisma/src/server.rs',
    'log.line': 95
  }
}
2020-03-11T12:13:00.773Z prisma-client Prisma Client call:
2020-03-11T12:13:00.774Z prisma-client prisma.zfah5_action_logs.create({
  data: {
    extension: 'ju',
    ip_address: 'nataj',
    item_id: 57,
    log_date: new Date('2079-12-15T01:51:36.680Z'),
    message: 'ca',
    message_language_key: 'unukaho',
    user_id: -1036
  }
})
2020-03-11T12:13:00.774Z prisma-client Generated request:
2020-03-11T12:13:00.774Z prisma-client mutation {
  createOnezfah5_action_logs(data: {
    extension: "ju"
    ip_address: "nataj"
    item_id: 57
    log_date: "2079-12-15T01:51:36.680Z"
    message: "ca"
    message_language_key: "unukaho"
    user_id: -1036
  }) {
    extension
    id
    ip_address
    item_id
    log_date
    message
    message_language_key
    user_id
  }
}

2020-03-11T12:13:01.244Z prisma-client Prisma Client call:
2020-03-11T12:13:01.244Z prisma-client prisma.zfah5_action_logs_extensions.create({
  data: {
    extension: 'dolbaw'
  }
})
2020-03-11T12:13:01.244Z prisma-client Generated request:
2020-03-11T12:13:01.244Z prisma-client mutation {
  createOnezfah5_action_logs_extensions(data: {
    extension: "dolbaw"
  }) {
    extension
    id
  }
}

2020-03-11T12:13:01.900Z prisma-client Prisma Client call:
2020-03-11T12:13:01.900Z prisma-client prisma.zfah5_action_logs_extensions.create({
  data: {
    extension: 'gokim'
  }
})
2020-03-11T12:13:01.900Z prisma-client Generated request:
2020-03-11T12:13:01.900Z prisma-client mutation {
  createOnezfah5_action_logs_extensions(data: {
    extension: "gokim"
  }) {
    extension
    id
  }
}

2020-03-11T12:13:02.369Z prisma-client Prisma Client call:
2020-03-11T12:13:02.370Z prisma-client prisma.zfah5_action_logs_users.create({
  data: {
    extensions: 'sab',
    notify: 1879,
    user_id: 4
  }
})
2020-03-11T12:13:02.370Z prisma-client Generated request:
2020-03-11T12:13:02.370Z prisma-client mutation {
  createOnezfah5_action_logs_users(data: {
    extensions: "sab"
    notify: 1879
    user_id: 4
  }) {
    extensions
    notify
    user_id
  }
}

2020-03-11T12:13:03.027Z prisma-client Prisma Client call:
2020-03-11T12:13:03.028Z prisma-client prisma.zfah5_action_logs_users.create({
  data: {
    extensions: 'nukonokan',
    notify: -1216,
    user_id: 5
  }
})
2020-03-11T12:13:03.028Z prisma-client Generated request:
2020-03-11T12:13:03.028Z prisma-client mutation {
  createOnezfah5_action_logs_users(data: {
    extensions: "nukonokan"
    notify: -1216
    user_id: 5
  }) {
    extensions
    notify
    user_id
  }
}

2020-03-11T12:13:03.498Z prisma-client Prisma Client call:
2020-03-11T12:13:03.499Z prisma-client prisma.zfah5_action_log_config.create({
  data: {
    id_holder: 'uhlog',
    table_name: 'sezsi',
    text_prefix: 'ju',
    title_holder: 'bu',
    type_alias: 'mahbu',
    type_title: 'wot'
  }
})
2020-03-11T12:13:03.499Z prisma-client Generated request:
2020-03-11T12:13:03.499Z prisma-client mutation {
  createOnezfah5_action_log_config(data: {
    id_holder: "uhlog"
    table_name: "sezsi"
    text_prefix: "ju"
    title_holder: "bu"
    type_alias: "mahbu"
    type_title: "wot"
  }) {
    id
    id_holder
    table_name
    text_prefix
    title_holder
    type_alias
    type_title
  }
}

2020-03-11T12:13:04.164Z prisma-client Prisma Client call:
2020-03-11T12:13:04.164Z prisma-client prisma.zfah5_action_log_config.create({
  data: {
    id_holder: 'cujduvtih',
    table_name: 'le',
    text_prefix: 'votevned',
    title_holder: 'esohogbi',
    type_alias: 'dadeip',
    type_title: 'riide'
  }
})
2020-03-11T12:13:04.164Z prisma-client Generated request:
2020-03-11T12:13:04.164Z prisma-client mutation {
  createOnezfah5_action_log_config(data: {
    id_holder: "cujduvtih"
    table_name: "le"
    text_prefix: "votevned"
    title_holder: "esohogbi"
    type_alias: "dadeip"
    type_title: "riide"
  }) {
    id
    id_holder
    table_name
    text_prefix
    title_holder
    type_alias
    type_title
  }
}

2020-03-11T12:13:04.634Z prisma-client Prisma Client call:
2020-03-11T12:13:04.634Z prisma-client prisma.zfah5_assets.create({
  data: {
    level: 418,
    lft: -359,
    name: 'gewse',
    parent_id: 779,
    rgt: -1355,
    rules: 'tuhdulhak',
    title: 'retijic'
  }
})
2020-03-11T12:13:04.634Z prisma-client Generated request:
2020-03-11T12:13:04.634Z prisma-client mutation {
  createOnezfah5_assets(data: {
    level: 418
    lft: -359
    name: "gewse"
    parent_id: 779
    rgt: -1355
    rules: "tuhdulhak"
    title: "retijic"
  }) {
    id
    level
    lft
    name
    parent_id
    rgt
    rules
    title
  }
}

2020-03-11T12:13:05.293Z prisma-client Prisma Client call:
2020-03-11T12:13:05.293Z prisma-client prisma.zfah5_assets.create({
  data: {
    level: -912,
    lft: -1089,
    name: 'bueh',
    parent_id: -1973,
    rgt: -1342,
    rules: 'mifdej',
    title: 'fef'
  }
})
2020-03-11T12:13:05.293Z prisma-client Generated request:
2020-03-11T12:13:05.293Z prisma-client mutation {
  createOnezfah5_assets(data: {
    level: -912
    lft: -1089
    name: "bueh"
    parent_id: -1973
    rgt: -1342
    rules: "mifdej"
    title: "fef"
  }) {
    id
    level
    lft
    name
    parent_id
    rgt
    rules
    title
  }
}

2020-03-11T12:13:05.764Z prisma-client Prisma Client call:
2020-03-11T12:13:05.764Z prisma-client prisma.zfah5_associations.create({
  data: {
    context: '3361fb0e-0de6-526e-ae0a-e4031aaef95d',
    id: 10,
    key: 'riumso'
  }
})
2020-03-11T12:13:05.764Z prisma-client Generated request:
2020-03-11T12:13:05.764Z prisma-client mutation {
  createOnezfah5_associations(data: {
    context: "3361fb0e-0de6-526e-ae0a-e4031aaef95d"
    id: 10
    key: "riumso"
  }) {
    context
    id
    key
  }
}

2020-03-11T12:13:06.422Z prisma-client Prisma Client call:
2020-03-11T12:13:06.422Z prisma-client prisma.zfah5_associations.create({
  data: {
    context: 'b7fdd67f-2505-5138-a78c-f3c6a84f5da6',
    id: 11,
    key: 'hepgu'
  }
})
2020-03-11T12:13:06.422Z prisma-client Generated request:
2020-03-11T12:13:06.422Z prisma-client mutation {
  createOnezfah5_associations(data: {
    context: "b7fdd67f-2505-5138-a78c-f3c6a84f5da6"
    id: 11
    key: "hepgu"
  }) {
    context
    id
    key
  }
}

2020-03-11T12:13:06.894Z prisma-client Prisma Client call:
2020-03-11T12:13:06.895Z prisma-client prisma.zfah5_banners.create({
  data: {
    alias: 'liedowa',
    catid: -1164,
    checked_out: 1699,
    checked_out_time: new Date('2108-07-22T06:13:39.174Z'),
    cid: 1269,
    clicks: 1929,
    clickurl: 'regduw',
    created: new Date('2110-07-28T15:11:20.278Z'),
    created_by: -603,
    created_by_alias: 'ewumovecu',
    custombannercode: 'iro',
    description: 'lavub',
    impmade: -865,
    imptotal: -1357,
    language: 'pol',
    metakey: 'harhi',
    metakey_prefix: 'ze',
    modified: new Date('2095-08-27T17:39:18.568Z'),
    modified_by: 170,
    name: 'log',
    ordering: -998,
    own_prefix: true,
    params: 'ukiipi',
    publish_down: new Date('2055-10-16T15:34:40.492Z'),
    publish_up: new Date('2039-11-07T17:29:16.572Z'),
    purchase_type: -1903,
    reset: new Date('2085-10-02T04:59:56.469Z'),
    state: 1816,
    sticky: -882,
    track_clicks: 1660,
    track_impressions: 1534,
    type: -519,
    version: 991
  }
})
2020-03-11T12:13:06.895Z prisma-client Generated request:
2020-03-11T12:13:06.895Z prisma-client mutation {
  createOnezfah5_banners(data: {
    alias: "liedowa"
    catid: -1164
    checked_out: 1699
    checked_out_time: "2108-07-22T06:13:39.174Z"
    cid: 1269
    clicks: 1929
    clickurl: "regduw"
    created: "2110-07-28T15:11:20.278Z"
    created_by: -603
    created_by_alias: "ewumovecu"
    custombannercode: "iro"
    description: "lavub"
    impmade: -865
    imptotal: -1357
    language: "pol"
    metakey: "harhi"
    metakey_prefix: "ze"
    modified: "2095-08-27T17:39:18.568Z"
    modified_by: 170
    name: "log"
    ordering: -998
    own_prefix: true
    params: "ukiipi"
    publish_down: "2055-10-16T15:34:40.492Z"
    publish_up: "2039-11-07T17:29:16.572Z"
    purchase_type: -1903
    reset: "2085-10-02T04:59:56.469Z"
    state: 1816
    sticky: -882
    track_clicks: 1660
    track_impressions: 1534
    type: -519
    version: 991
  }) {
    alias
    catid
    checked_out
    checked_out_time
    cid
    clicks
    clickurl
    created
    created_by
    created_by_alias
    custombannercode
    description
    id
    impmade
    imptotal
    language
    metakey
    metakey_prefix
    modified
    modified_by
    name
    ordering
    own_prefix
    params
    publish_down
    publish_up
    purchase_type
    reset
    state
    sticky
    track_clicks
    track_impressions
    type
    version
  }
}

2020-03-11T12:13:07.560Z prisma-client Prisma Client call:
2020-03-11T12:13:07.561Z prisma-client prisma.zfah5_banners.create({
  data: {
    alias: 'ohi',
    catid: 211,
    checked_out: 1867,
    checked_out_time: new Date('2117-07-31T20:04:17.305Z'),
    cid: -460,
    clicks: -1237,
    clickurl: 'kiliov',
    created: new Date('2113-09-18T01:05:12.615Z'),
    created_by: 685,
    created_by_alias: 'fejuhera',
    custombannercode: 'lihakhup',
    description: 'patofcok',
    impmade: 1183,
    imptotal: -1797,
    language: 'kajdinbel',
    metakey: 'uhu',
    metakey_prefix: 'bebah',
    modified: new Date('2074-05-04T07:31:49.769Z'),
    modified_by: -914,
    name: 'tic',
    ordering: 1368,
    own_prefix: true,
    params: 'mir',
    publish_down: new Date('2033-08-23T03:58:58.516Z'),
    publish_up: new Date('2052-09-02T19:23:16.433Z'),
    purchase_type: -244,
    reset: new Date('2027-09-08T00:11:57.080Z'),
    state: 1344,
    sticky: -287,
    track_clicks: 784,
    track_impressions: 754,
    type: -364,
    version: -1768
  }
})
2020-03-11T12:13:07.561Z prisma-client Generated request:
2020-03-11T12:13:07.561Z prisma-client mutation {
  createOnezfah5_banners(data: {
    alias: "ohi"
    catid: 211
    checked_out: 1867
    checked_out_time: "2117-07-31T20:04:17.305Z"
    cid: -460
    clicks: -1237
    clickurl: "kiliov"
    created: "2113-09-18T01:05:12.615Z"
    created_by: 685
    created_by_alias: "fejuhera"
    custombannercode: "lihakhup"
    description: "patofcok"
    impmade: 1183
    imptotal: -1797
    language: "kajdinbel"
    metakey: "uhu"
    metakey_prefix: "bebah"
    modified: "2074-05-04T07:31:49.769Z"
    modified_by: -914
    name: "tic"
    ordering: 1368
    own_prefix: true
    params: "mir"
    publish_down: "2033-08-23T03:58:58.516Z"
    publish_up: "2052-09-02T19:23:16.433Z"
    purchase_type: -244
    reset: "2027-09-08T00:11:57.080Z"
    state: 1344
    sticky: -287
    track_clicks: 784
    track_impressions: 754
    type: -364
    version: -1768
  }) {
    alias
    catid
    checked_out
    checked_out_time
    cid
    clicks
    clickurl
    created
    created_by
    created_by_alias
    custombannercode
    description
    id
    impmade
    imptotal
    language
    metakey
    metakey_prefix
    modified
    modified_by
    name
    ordering
    own_prefix
    params
    publish_down
    publish_up
    purchase_type
    reset
    state
    sticky
    track_clicks
    track_impressions
    type
    version
  }
}

2020-03-11T12:13:08.042Z prisma-client Prisma Client call:
2020-03-11T12:13:08.042Z prisma-client prisma.zfah5_banner_clients.create({
  data: {
    checked_out: -1307,
    checked_out_time: new Date('2035-11-14T06:14:32.093Z'),
    contact: 'vutuwom',
    email: 'wibse',
    extrainfo: 'daj',
    metakey: 'ca',
    metakey_prefix: 'ez',
    name: 'nazinef',
    own_prefix: -141,
    purchase_type: -265,
    state: 599,
    track_clicks: -406,
    track_impressions: -1808
  }
})
2020-03-11T12:13:08.042Z prisma-client Generated request:
2020-03-11T12:13:08.043Z prisma-client mutation {
  createOnezfah5_banner_clients(data: {
    checked_out: -1307
    checked_out_time: "2035-11-14T06:14:32.093Z"
    contact: "vutuwom"
    email: "wibse"
    extrainfo: "daj"
    metakey: "ca"
    metakey_prefix: "ez"
    name: "nazinef"
    own_prefix: -141
    purchase_type: -265
    state: 599
    track_clicks: -406
    track_impressions: -1808
  }) {
    checked_out
    checked_out_time
    contact
    email
    extrainfo
    id
    metakey
    metakey_prefix
    name
    own_prefix
    purchase_type
    state
    track_clicks
    track_impressions
  }
}

2020-03-11T12:13:08.698Z prisma-client Prisma Client call:
2020-03-11T12:13:08.698Z prisma-client prisma.zfah5_banner_clients.create({
  data: {
    checked_out: 464,
    checked_out_time: new Date('2084-12-28T01:15:22.015Z'),
    contact: 'pivvod',
    email: 'opbun',
    extrainfo: 'anoso',
    metakey: 'am',
    metakey_prefix: 'tettufja',
    name: 'la',
    own_prefix: -1845,
    purchase_type: -1623,
    state: 473,
    track_clicks: 732,
    track_impressions: -654
  }
})
2020-03-11T12:13:08.698Z prisma-client Generated request:
2020-03-11T12:13:08.698Z prisma-client mutation {
  createOnezfah5_banner_clients(data: {
    checked_out: 464
    checked_out_time: "2084-12-28T01:15:22.015Z"
    contact: "pivvod"
    email: "opbun"
    extrainfo: "anoso"
    metakey: "am"
    metakey_prefix: "tettufja"
    name: "la"
    own_prefix: -1845
    purchase_type: -1623
    state: 473
    track_clicks: 732
    track_impressions: -654
  }) {
    checked_out
    checked_out_time
    contact
    email
    extrainfo
    id
    metakey
    metakey_prefix
    name
    own_prefix
    purchase_type
    state
    track_clicks
    track_impressions
  }
}

Error: Unsupported ID type "DateTime"
    at getMockDataForField (/home/runner/work/introspection-engine-output/prisma-test-utils/src/static/seed.ts:1072:21)
    at Array.reduce (<anonymous>)
    at getMockForTask (/home/runner/work/introspection-engine-output/prisma-test-utils/src/static/seed.ts:986:10)
    at /home/runner/work/introspection-engine-output/prisma-test-utils/src/static/seed.ts:905:65
    at Generator.next (<anonymous>)
    at /home/runner/work/introspection-engine-output/prisma-test-utils/dist/static/seed.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/home/runner/work/introspection-engine-output/prisma-test-utils/dist/static/seed.js:4:12)
    at iterate (/home/runner/work/introspection-engine-output/prisma-test-utils/dist/static/seed.js:633:24)
    at /home/runner/work/introspection-engine-output/prisma-test-utils/src/static/seed.ts:947:30
===end seed===
2020-03-11T12:13:09.170Z engine Stopping Prisma engine
2020-03-11T12:13:09.212Z getos { version: 'OpenSSL 1.1.1d  10 Sep 2019\n' }
2020-03-11T12:13:09.212Z getos { ls: '' }
2020-03-11T12:13:09.212Z getos { platform: 'linux', libssl: '1.1.x' }
maticzav commented 4 years ago

This is a test-utils error. Currently it only supports String and Int ids. Any suggestions on how to make dates unique?

divyenduz commented 4 years ago

No idea yet! For now, we are only creating 2 records so maybe just removing this guardrail works already! But I can't think of any other way than "peek and regenerate date on collision".

janpio commented 4 years ago

Currently it only supports String and Int ids. Any suggestions on how to make dates unique?

What is the connection between DateTime and ids? The @id of this table is an Int, and the DateTime field is not unique.

Am I missing something?

divyenduz commented 4 years ago

I might be wrong (Matic can confirm) but I think the error comes from the next table/model. test-utils crashes when forming the query for it.

I will look into the code later today and validate this.

janpio commented 4 years ago

That would make sense:

https://github.com/prisma/database-schema-examples/blob/cdba7b880b5d9cba9ec5c97c83aa083ea85d89c3/mysql/joomla/schema.sql#L162-L175`

CREATE TABLE `zfah5_banner_tracks` (
  `track_date` datetime NOT NULL,
  `track_type` int(10) unsigned NOT NULL,
  `banner_id` int(10) unsigned NOT NULL,
  `count` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`track_date`,`track_type`,`banner_id`),
  KEY `idx_track_date` (`track_date`),
  KEY `idx_track_type` (`track_type`),
  KEY `idx_banner_id` (`banner_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

https://github.com/prisma/introspection-engine-output/blob/17c81171e67e1e45312668a9b38b977dc061996b/mysql_public_test_utils/joomla.log#L135-L145

model zfah5_banner_tracks {
  banner_id  Int
  count      Int      @default(0)
  track_date DateTime
  track_type Int

  @@id([track_date, track_type, banner_id])
  @@index([banner_id], name: "idx_banner_id")
  @@index([track_date], name: "idx_track_date")
  @@index([track_type], name: "idx_track_type")
}

@@id and one of the field is DateTime.

We could probably get away with choosing a random DateTime value here, with the little amount of data we create? (Could test-utils maybe have a list of previously generated values for the column, and recreate if a clash is encountered?)

maticzav commented 4 years ago

@janpio I suggest we use iteration number as identifier for now and change the min max property of the date accordingly.

I am still unsure I understand the bug behind it though. Is there a section in the Prisma spec that supports having DateTime as id?

Besides that, I’ve been thinking about how to handle unique constrains. I think we should focus on making sure that there are enough unique values that we can produce in the pool before even starting the test-utils. For example, if you are trying to specify how to generate unique field for 100 people, but your function only packs 100 unique values, it might be extremely hard for test-utils to find all the unique values by iterating over and over. Having only 50 unique values to choose from might be even bigger problem. I think we could solve that by accepting an array of unique fields instead of a function or a static value, and let people specify it that way. On the other hand, chance.js (our mocking toolkit), implements a unique function that we can use as a good default.

What do you think?

janpio commented 4 years ago

I am still unsure I understand the bug behind it though. Is there a section in the Prisma spec that supports having DateTime as id?

If databases do, Prisma needs to have a way to handle that.

What do you think?

I don't understand any of that - so I am assume it makes sense.