Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: javascript and typescript migrations #181

Merged
merged 11 commits into from
Apr 16, 2020
Merged

feat: javascript and typescript migrations #181

merged 11 commits into from
Apr 16, 2020

Conversation

mmkal
Copy link
Owner

@mmkal mmkal commented Apr 16, 2020

fixes #45 and #141

@mmkal mmkal merged commit aa3b6e3 into master Apr 16, 2020
@mmkal mmkal deleted the migrationResolver branch April 16, 2020 10:52
@karlhorky
Copy link

Just trying this... TypeScript support is not working:

Unhandled rejection /Users/k/p/next.js-with-slonik/migrations/2019-10-23T08-22.database-setup.ts:10
type MigrationOptions = {
     ^^^^^^^^^^^^^^^^

SyntaxError: Unexpected identifier
    at wrapSafe (internal/modules/cjs/loader.js:1063:16)
    at Module._compile (internal/modules/cjs/loader.js:1111:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:996:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Module.require (internal/modules/cjs/loader.js:1036:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.scriptResolver (/Users/k/p/next.js-with-slonik/node_modules/@slonik/migrator/dist/index.js:25:32)
    at migrationResolver (/Users/k/p/next.js-with-slonik/node_modules/@slonik/migrator/dist/index.js:46:45)
    at Object.customResolver (/Users/k/p/next.js-with-slonik/node_modules/@slonik/migrator/dist/index.js:66:37)
    at Migration.migration (/Users/k/p/next.js-with-slonik/node_modules/umzug/lib/migration.js:60:38)
    at /Users/k/p/next.js-with-slonik/node_modules/umzug/lib/migration.js:121:37
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/Users/k/p/next.js-with-slonik/node_modules/umzug/lib/migration.js:9:103)
    at _next (/Users/k/p/next.js-with-slonik/node_modules/umzug/lib/migration.js:11:194)
    at /Users/k/p/next.js-with-slonik/node_modules/umzug/lib/migration.js:11:364

@karlhorky
Copy link

Would also like to use ES module imports, eg:

import type { DatabasePoolConnectionType, SqlTaggedTemplateType } from 'slonik';
import { createPool } from 'slonik';

These are also not working:

Unhandled rejection /Users/k/p/next.js-with-slonik/migrations/2019-10-23T08-22.database-setup.ts:3
import type { DatabasePoolConnectionType, SqlTaggedTemplateType } from 'slonik';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1063:16)
    at Module._compile (internal/modules/cjs/loader.js:1111:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:996:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Module.require (internal/modules/cjs/loader.js:1036:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.scriptResolver (/Users/k/p/next.js-with-slonik/node_modules/@slonik/migrator/dist/index.js:25:32)
    at migrationResolver (/Users/k/p/next.js-with-slonik/node_modules/@slonik/migrator/dist/index.js:46:45)
    at Object.customResolver (/Users/k/p/next.js-with-slonik/node_modules/@slonik/migrator/dist/index.js:66:37)
    at Migration.migration (/Users/k/p/next.js-with-slonik/node_modules/umzug/lib/migration.js:60:38)
    at /Users/k/p/next.js-with-slonik/node_modules/umzug/lib/migration.js:121:37
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/Users/k/p/next.js-with-slonik/node_modules/umzug/lib/migration.js:9:103)
    at _next (/Users/k/p/next.js-with-slonik/node_modules/umzug/lib/migration.js:11:194)
    at /Users/k/p/next.js-with-slonik/node_modules/umzug/lib/migration.js:11:364

My tsconfig.json is set up to allow ES Modules: https://github.com/karlhorky/next.js-with-slonik/blob/master/tsconfig.json

@karlhorky
Copy link

Anyway, going to use JavaScript for now.

@mmkal
Copy link
Owner Author

mmkal commented Apr 16, 2020

You probably need ts-node. See the "JavaScript and TypeScript migrations" section of the readme:

Note: if writing migrations in typescript, you will likely want to use a tool like ts-node to enable loading typescript modules. You can either add require('ts-node/register/transpile-only') at the top of your migrate.js file, or run node -r ts-node/register/transpile-only migrate ... instead of node migrate ....

@karlhorky
Copy link

Ah ok, yeah that's a bit much, maybe at some point later...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Passing data to SQL
2 participants