Discourse での旧投稿 ID の保持をインポート

The import script saves the import id in a post custom field. You can use it to create permalinks. Several importers do that. You can look at others for examples.