{"_id":"@acomagu/strapi-data-migrator","_rev":"1-48d9985f88f6e8915f29307662b1e481","name":"@acomagu/strapi-data-migrator","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.1":{"name":"@acomagu/strapi-data-migrator","version":"0.0.1","type":"module","bin":{"strapi-generate-types":"generate-types.js","strapi-dump-data":"dump-data.js","strapi-import-data":"import-data.js","strapi-generate-transformer":"generate-transformer.js"},"dependencies":{"chalk":"^5.3.0","change-case":"^4.1.2","glob":"^10.3.3","pluralize":"^8.0.0","toposort":"^2.0.2","ts-morph":"^19.0.0","typia":"^4.1.8","zx":"^7.2.3"},"peerDependencies":{"strapi":"^3.0.0"},"devDependencies":{"@types/pluralize":"^0.0.30","@types/toposort":"^2.0.3","strapi-database":"^3.6.11","typescript":"^5.1.6"},"_id":"@acomagu/strapi-data-migrator@0.0.1","gitHead":"f400573d632b521b4716ecec7e51e29ca94da0fc","description":"This helps you to dump data from Strapi, transform it to fit the destination Strapi and import it.","_nodeVersion":"20.5.0","_npmVersion":"9.8.1","dist":{"integrity":"sha512-+6LbRUa2iawTrHvOvYCm7HQNm2yMr6EtoQeL/Adjih5sFrR+F0a5ElgsP0rruxlVsuU/meZ1NNkDsjRc9NQEOg==","shasum":"154fcad29462c30f754a098383267e11459924fa","tarball":"https://registry.npmjs.org/@acomagu/strapi-data-migrator/-/strapi-data-migrator-0.0.1.tgz","fileCount":14,"unpackedSize":113282,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDnO4LIR8oxXi527uSSku7PIznRW7KIbagvZTu4haVhHwIhAJkPugnYGl7Ym4TqJIHh2ho4g64lbV1v5bx26T3bISVL"}]},"_npmUser":{"name":"acomagu","email":"acomagu@gmail.com"},"directories":{},"maintainers":[{"name":"acomagu","email":"acomagu@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/strapi-data-migrator_0.0.1_1692505577572_0.04885225132177906"},"_hasShrinkwrap":false},"0.0.2":{"name":"@acomagu/strapi-data-migrator","version":"0.0.2","type":"module","bin":{"strapi-generate-types":"generate-types.js","strapi-dump-data":"dump-data.js","strapi-import-data":"import-data.js","strapi-generate-transformer":"generate-transformer.js"},"dependencies":{"chalk":"^5.3.0","change-case":"^4.1.2","glob":"^10.3.3","pluralize":"^8.0.0","toposort":"^2.0.2","ts-morph":"^19.0.0","typia":"^4.1.8","zx":"^7.2.3"},"peerDependencies":{"strapi":"^3.0.0"},"devDependencies":{"@types/pluralize":"^0.0.30","@types/toposort":"^2.0.3","strapi-database":"^3.6.11","typescript":"^5.1.6"},"_id":"@acomagu/strapi-data-migrator@0.0.2","gitHead":"aaa3be8aaf45aa4215efacaa39c27a6fb42dae4d","description":"This helps you to dump data from Strapi, transform it to fit the destination Strapi and import it.","_nodeVersion":"20.5.1","_npmVersion":"10.1.0","dist":{"integrity":"sha512-ALQzlibDNsaageLPc5y6Bhh8CwQR5SUtdlBuDqbt+T/MYAHpf8pR/0RaPI2d52JVbcnoHyKEXz4HDxnj1pZBiA==","shasum":"76ad0cbfb6bb73f1324d8d4a4b9353797da3805e","tarball":"https://registry.npmjs.org/@acomagu/strapi-data-migrator/-/strapi-data-migrator-0.0.2.tgz","fileCount":17,"unpackedSize":138175,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBbIMtn0lBM7njQZxXISal1Z1fR9yD2f7iPpbjwLX+MqAiABWKGufz5VST3REuLuQvL9Hj5bULoVTLdhyBeqZMeB2A=="}]},"_npmUser":{"name":"acomagu","email":"acomagu@gmail.com"},"directories":{},"maintainers":[{"name":"acomagu","email":"acomagu@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/strapi-data-migrator_0.0.2_1696495640164_0.8076613727560138"},"_hasShrinkwrap":false}},"time":{"created":"2023-08-20T04:26:17.493Z","0.0.1":"2023-08-20T04:26:17.743Z","modified":"2023-10-05T08:47:20.589Z","0.0.2":"2023-10-05T08:47:20.425Z"},"maintainers":[{"name":"acomagu","email":"acomagu@gmail.com"}],"description":"This helps you to dump data from Strapi, transform it to fit the destination Strapi and import it.","readme":"# The data migrator from Strapi V3 to Strapi V3\n\nThis helps you to dump data from Strapi, transform it to fit the destination Strapi and import it.\n\nThe npm package includes the 4 commands:\n\n- `strapi-dump-data`: Dumps all data as JSON from Strapi.\n- `strapi-generate-types`: Generates TypeScript types of the data.\n- `strapi-generate-transformer`: Generate a boilerplate helps you to write your own data transformer(fully typed TypeScript code).\n- `strapi-import-data`: Imports a JSON data into Strapi.\n\n## Typical Usecase: Dump data from Strapi, transform and import to another Strapi.\n\nThis example assumes that you have two Strapi projects, one is the source and the other is the destination.\n\n```\n.\n├── source-strapi/\n└── destination-strapi/\n```\n\n### Step 1: Dump data and generate types from the data source Strapi\n\nFirst, install the npm package **at the source Strapi source code**:\n\n```\ncd source-strapi\nnpm install -D @acomagu/strapi-data-migrator\n```\n\nThen, dump data and generate the types:\n\n```\nnpx strapi-dump-data\nnpx strapi-generate-types\n```\n\n`data.json` and `models.ts` will be generated.\n\nYou can export data through REST API also by adding flag like `npx strapi-dump-data --useapi <URL>`, but it's not recommended. The internal data of some plugins can't be fetched, and if the API controller is customized, this tool may not be able to find the endpoint URL correctly.\n\n### Step 2: Generate types from the destination Strapi\n\n**Move to the destination Strapi directory** and generates `models.ts` for destination Strapi also:\n\n```\ncd ../destination-strapi\nnpm install -D @acomagu/strapi-data-migrator\nnpx strapi-generate-types\n```\n\n### Step 3: Generate transformer\n\n**Still in the destination Strapi directory,** execute:\n\n```\nnpx strapi-generate-transformer ../data-transformer ../source-strapi/models.ts ./models.ts\n```\n\nThis command creates the boilerplate at `../data-transformer`.\n\n```\n.\n├── source-strapi/\n├── destination-strapi/\n└── data-transformer/\n    ├── index.ts\n    ├── sourceModels.ts\n    ├── destinationModels.ts\n    ├── package.json\n    └── node_modules/\n```\n\nAnd copy `data.json` at Step 1 into it.\n\n```\ncp ../source-strapi/data.json ../data-transformer\n```\n\n### Step 4: Complete the transformer and run\n\nThe generated `index.ts` is like this:\n\n```typescript\nimport fs from 'fs';\nimport typia from 'typia';\nimport * as source from './sourceModels.js';\nimport * as dest from './destModels.js';\n\ntype Data<T> = { [Name in keyof T]: T[Name][] };\n\n// import data\nconst uncheckedData = JSON.parse((fs.readFileSync('data.json')).toString());\nconst data = typia.assert<Data<source.ModelByName>>(uncheckedData);\n\n// Transform data to destination format.\n// Write code to transform data here and fix all type errors.\n// For example, if the destination user model has `first_name` and `last_name` fields instead of `name`:\n//\n// ```\n//   \"user\": data.user.map((user) => ({\n//     ...user,\n//     first_name: user.name.split(' ')[0],\n//     last_name: user.name.split(' ')[1],\n//   })),\n// ```\nlet transformedData: Data<dest.ModelByName> = {\n  'post': data['post'],\n  'user': data['user'],\n  ...\n};\n\n\n// Save data to file as JSON to be imported to destination Strapi.\nfs.writeFileSync('transformedData.json', JSON.stringify(transformedData));\n```\n\nLet's try running it.\n\n```\ncd ../data-transformer\nnpm start\n```\n\nIf the source and destination Strapi models are different, TypeScript compile error should be present.\n\nFixing them is your task. Write data migration code to fit to the destination Strapi model.\n\nIf the conversion is successful, `transformedData.json` will be generated.\n\n### Step 5: Import data to destination Strapi\n\nDuring import, several data transformations are performed (mainly ID rewriting).\n\nWe recommend that you pre-check your data with `--dry-run` before actually running the import.\n\n```\ncd ../destination-strapi\ncp ../transformedData.json ./data.json\nnpx strapi-import-data --dry-run\n```\n\n`written-data.json` are generated. If it seems OK, then actually run the import.\n\n```\nnpx strapi-import-data\n```\n\n## Trouble Shooting\n\n### Importing was succeeded, but data is not present in admin panel\n\nCheck internationalization setting. Setting up the same as source Strapi may display the data.\n\n### Error while importing: `Cannot find new id for ...`\n\nThe entry has relation to other entry, but can't find the related entry. The relation field in which the error occurred is null, but the other fields are imported.\n\nCorrect the field mannualy after importing or correct them to the correct relation in the Transform step.\n\n### Error while importing: `Couldn't create the item because of duplication error`\n\nEntry could not be imported because one of the fields in the destination model schema had a unique constraint, which was violated.\n\n### IDs of entries are changed\n\nThis is by design.\n","readmeFilename":"README.md"}