halvardssm / deno-nessie

A modular Deno library for PostgreSQL, MySQL, MariaDB and SQLite migrations
MIT License
527 stars 31 forks source link

[BUG] Unable to run migration, cannot import module #117

Closed ConorHaining closed 3 years ago

ConorHaining commented 3 years ago

System (please complete the following information):

Describe the bug A clear and concise description of what the bug is.

When attempting to run a migration, and this is currently the only migration, I am unable to do so as the path for the migration is being pulled from deno.land rather than the local filesystem. TypeError: An unsupported media type was attempted to be imported as a module.

To Reproduce Steps to reproduce the behavior:

  1. Create a migration
  2. Fill it with a query
  3. Run deno run -A --unstable https://deno.land/x/nessie/cli.ts migrate

Expected behavior A clear and concise description of what you expected to happen.

Migration happens and query is executed on the database

Screenshots or error log If applicable, add screenshots or error log to help explain your problem.

deno run -A --unstable https://deno.land/x/nessie/cli.ts migrate -d
State: 
[ true, "file:///path/to/file/src/nessie.config.ts" ]
Checking config path
Amount pre: 
undefined
Latest migrations: 
undefined
Filtered and sorted migration files: 
[ "20210513164926-createvehiclemovements.ts" ]
TypeError: An unsupported media type was attempted to be imported as a module.
  Specifier: https://deno.land/path/to/file/src/db/migrations/20210513164926-createvehiclemovements.ts
  MediaType: Unknown
    at async ClientPostgreSQL._migrationHandler (https://deno.land/x/nessie@1.3.1/clients/AbstractClient.ts:222:39)
    at async ClientPostgreSQL._migrate (https://deno.land/x/nessie@1.3.1/clients/AbstractClient.ts:97:9)
    at async ClientPostgreSQL.migrate (https://deno.land/x/nessie@1.3.1/clients/ClientPostgreSQL.ts:106:5)
    at async Command.fn (https://deno.land/x/nessie@1.3.1/cli.ts:60:7)
    at async Command.execute (https://deno.land/x/cliffy@v0.18.2/command/command.ts:973:7)
    at async Command.parse (https://deno.land/x/cliffy@v0.18.2/command/command.ts:896:16)
    at async Command.parse (https://deno.land/x/cliffy@v0.18.2/command/command.ts:848:16)
    at async cli (https://deno.land/x/nessie@1.3.1/cli.ts:13:3)
    at async run (https://deno.land/x/nessie@1.3.1/cli.ts:161:5)

Additional context Add any other context about the problem here. Attaching the migration file. 20210513164926-createvehiclemovements.txt

halvardssm commented 3 years ago

Hi @ConorHaining ! Thanks for reporting this bug. I can't immediately find the fix, so I will have to investigate a bit, but I will keep you updated.

beagleknight commented 3 years ago

Hello! I am taking a look at it (even I am a super Deno noob πŸ˜… ). I think I know where the bug comes from. If I change my nessie.config.ts like this it works (I cloned this repo to my local machine):

diff --git a/backend/nessie.config.ts b/backend/nessie.config.ts
index 4254205..d9e6668 100644
--- a/backend/nessie.config.ts
+++ b/backend/nessie.config.ts
@@ -2,7 +2,7 @@ import {
   ClientOptions,
   ClientPostgreSQL,
   NessieConfig,
-} from "https://deno.land/x/nessie/mod.ts";
+} from "../../deno-nessie/mod.ts";

I assume there is something related to the path where we are importing the ClientPostgreSQL. I will try to fix it myself πŸ’ͺ

Update: I don't have any idea how to fix it, sorry! I think it is something related to the resolve function when resolving paths or something, but I am not certain.

halvardssm commented 3 years ago

Thats the conclusion I also reached. The issue was related to another bug from last week, but it should be good with v1.3.2 πŸ’ͺ🏻

ConorHaining commented 3 years ago

Thank you so much @halvardssm, confirmed it's working in v1.3.2 πŸ‘