(function (global) {
  global.ARQ = global.ARQ || {};
  ARQ.migrations = {
    run: function (project) {
      if (!project || typeof project !== 'object') return project;
      var v = project.schemaVersion | 0;
      if (v < 1) project.schemaVersion = 1;
      if (!project.hoja_activa_id && project.hojas && project.hojas[0]) {
        project.hoja_activa_id = project.hojas[0].id;
      }
      if (!project.materiales) project.materiales = [];
      if (!project.chat_ia) project.chat_ia = [];
      if (!project.exportaciones) project.exportaciones = [];
      if (!project.metadatos) project.metadatos = {};
      return project;
    },
  };
})(typeof window !== 'undefined' ? window : this);
