{"version":3,"file":"mysql-migrator.mjs","sources":["../../../src/mysql-migrator.ts"],"sourcesContent":["import {\n  RdbmsSessionStorageMigrator,\n  RdbmsSessionStorageMigratorOptions,\n  MigrationOperation,\n} from '@shopify/shopify-app-session-storage';\n\nimport {MySqlConnection} from './mysql-connection';\n\nexport class MySqlSessionStorageMigrator extends RdbmsSessionStorageMigrator {\n  constructor(\n    dbConnection: MySqlConnection,\n    opts: Partial<RdbmsSessionStorageMigratorOptions> = {},\n    migrations: MigrationOperation[],\n  ) {\n    super(dbConnection, opts, migrations);\n  }\n\n  async initMigrationPersistence(): Promise<void> {\n    const discardCreateTable = await this.connection.hasTable(\n      this.options.migrationDBIdentifier,\n    );\n\n    if (!discardCreateTable) {\n      const migration = `\n      CREATE TABLE ${this.options.migrationDBIdentifier} (\n        ${\n          this.getOptions().migrationNameColumnName\n        } varchar(255) NOT NULL PRIMARY KEY\n    );`;\n\n      await this.connection.query(migration, []);\n    }\n  }\n\n  /**\n   * This is overriden from the abstract class has the result type is different for mysql\n   * @param migrationName - the migration name we want to check in the table\n   * @returns true if the 'migrationName' has been found in the migrations table, false otherwise\n   */\n  async hasMigrationBeenApplied(migrationName: string): Promise<boolean> {\n    await this.ready;\n\n    const query = `\n      SELECT * FROM ${this.options.migrationDBIdentifier}\n      WHERE ${this.getOptions().migrationNameColumnName} = \n        ${this.connection.getArgumentPlaceholder(1)};\n    `;\n\n    const [rows] = await this.connection.query(query, [migrationName]);\n\n    return Array.isArray(rows) && rows.length === 1;\n  }\n}\n"],"names":[],"mappings":";;AAQM,MAAO,2BAA4B,SAAQ,2BAA2B,CAAA;AAC1E,IAAA,WAAA,CACE,YAA6B,EAC7B,IAAA,GAAoD,EAAE,EACtD,UAAgC,EAAA;AAEhC,QAAA,KAAK,CAAC,YAAY,EAAE,IAAI,EAAE,UAAU,CAAC;IACvC;AAEA,IAAA,MAAM,wBAAwB,GAAA;AAC5B,QAAA,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CACvD,IAAI,CAAC,OAAO,CAAC,qBAAqB,CACnC;QAED,IAAI,CAAC,kBAAkB,EAAE;AACvB,YAAA,MAAM,SAAS,GAAG;qBACH,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAA;AAE7C,QAAA,EAAA,IAAI,CAAC,UAAU,EAAE,CAAC,uBACpB,CAAA;OACD;YAED,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,CAAC;QAC5C;IACF;AAEA;;;;AAIG;IACH,MAAM,uBAAuB,CAAC,aAAqB,EAAA;QACjD,MAAM,IAAI,CAAC,KAAK;AAEhB,QAAA,MAAM,KAAK,GAAG;sBACI,IAAI,CAAC,OAAO,CAAC,qBAAqB;AAC1C,YAAA,EAAA,IAAI,CAAC,UAAU,EAAE,CAAC,uBAAuB,CAAA;AAC7C,QAAA,EAAA,IAAI,CAAC,UAAU,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAA;KAC9C;AAED,QAAA,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,aAAa,CAAC,CAAC;AAElE,QAAA,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;IACjD;AACD;;;;"}