wdbsb
wdbsb
DTDrizzle Team
Created by wdbsb on 8/8/2023 in #help
Baseline for introspected schema
Thanks for trying that. I'll try it on another computer to see if I just have some wierd configuration problem.
48 replies
DTDrizzle Team
Created by wdbsb on 8/8/2023 in #help
Baseline for introspected schema
Thanks Andrew
48 replies
DTDrizzle Team
Created by wdbsb on 8/8/2023 in #help
Baseline for introspected schema
@Andrew Sherman You must be really busy. Is there anyone else who can help with this?
48 replies
DTDrizzle Team
Created by wdbsb on 8/8/2023 in #help
Baseline for introspected schema
Hey @Andrew Sherman, I hate to keep bugging you, but have you had a chance to look at this?
48 replies
DTDrizzle Team
Created by wdbsb on 8/8/2023 in #help
Baseline for introspected schema
@Andrew Sherman Did you get to look at this problem?
48 replies
DTDrizzle Team
Created by wdbsb on 8/8/2023 in #help
Baseline for introspected schema
Thanks Andrew. I really appreciate your help.
48 replies
DTDrizzle Team
Created by wdbsb on 8/8/2023 in #help
Baseline for introspected schema
@Andrew Sherman Were you able to reproduce the migration that drops all of the tables?
48 replies
DTDrizzle Team
Created by wdbsb on 8/8/2023 in #help
Baseline for introspected schema
"drizzle-kit": "^0.19.13",
48 replies
DTDrizzle Team
Created by wdbsb on 8/8/2023 in #help
Baseline for introspected schema
@Andrew Sherman - I may have celebrated too soon! Applying the initial migration worked perfectly, but the next one dropped all of the tables. Here's what I did: I added a new column called 'test' to the "aa" table in schema.ts Then I set breakpoints back to true in drizzle.config.ts, Finally I ran "npx drizzle-kit generate:mysql" and got this:
DROP TABLE `aa`;--> statement-breakpoint
DROP TABLE `bb`;
DROP TABLE `aa`;--> statement-breakpoint
DROP TABLE `bb`;
Can you reproduce this?
48 replies
DTDrizzle Team
Created by wdbsb on 8/8/2023 in #help
Baseline for introspected schema
@Andrew Sherman That worked! Thanks for looking into this.
48 replies
DTDrizzle Team
Created by wdbsb on 8/8/2023 in #help
Baseline for introspected schema
@Andrew Sherman Thanks! I'll give it a try. And get back to you.
48 replies
DTDrizzle Team
Created by wdbsb on 8/8/2023 in #help
Baseline for introspected schema
Forgot to mention, this is MySql 8.0.28
48 replies
DTDrizzle Team
Created by wdbsb on 8/8/2023 in #help
Baseline for introspected schema
OK, got it * Clone https://github.com/wdbsb/drizzle_simple.git * Create a MySql database called drizzle_simple * Use the existingdb.sql script to create the 'existing' tables * Update the DB credentials in drizzle.config.ts and index.ts * npm install * npx drizzle-kit introspect:mysql * npx tsc * node index.js * It should fail with a complaint about the comments * Delete the "bb" and __drizzle_migrations tables leaving only the "aa" table * Delete the drizzle folder * npx drizzle-kit introspect:mysql * node index.js It should work with one table
48 replies
DTDrizzle Team
Created by wdbsb on 8/8/2023 in #help
Baseline for introspected schema
Thanks @Andrew Sherman, I'll put that together! Can you verify that this is the correct way to create the __drizzle_migrations table and mark the initial migration (commented out) created by the introspection as applied? 1. Run "npx drizzle-kit introspect:mysql" to create schema.ts and the initial commented-out migration SQL file. 2. Run code such a the code above so do a migration that does not change the exiting schema other than to add the __drizzle_migrations table
48 replies
DTDrizzle Team
Created by wdbsb on 8/8/2023 in #help
Baseline for introspected schema
@bloberenober Did you get a chance to look at this?
48 replies
DTDrizzle Team
Created by wdbsb on 8/8/2023 in #help
Baseline for introspected schema
Now it gets really weird. To try a real migration I added a column to one of the tables in schema.ts and ran "drizzle-kit generate:mysql". The resulting migration drops all of the tables in the database!
48 replies
DTDrizzle Team
Created by wdbsb on 8/8/2023 in #help
Baseline for introspected schema
I figured out the hanging. I had assumed from the examples that migrate() closes database connection but apparently it does not. A call to connection.end() seems to fix it. Can anyone confirm that closing the database is the responsibility of the caller?
48 replies
DTDrizzle Team
Created by wdbsb on 8/8/2023 in #help
Baseline for introspected schema
That is followed by the SQL code commented out with /* */ style comments. If I leave the first two comments and delete the commented out creates then running the migration will add the __drizzle_migrations table and add the row that represents that initial migration. The weird thing is that my migration program just hangs after adding that row. Here's the program: import { drizzle } from "drizzle-orm/mysql2"; import mysql from "mysql2/promise"; import { migrate } from 'drizzle-orm/mysql2/migrator'; const connection = await mysql.createConnection({ user: "redacted", password: "redacted", host: "127.0.0.1", port: 3306, database: "redacted", }); const db = drizzle(connection, {logger: false} ); // this will automatically run needed migrations on the database await migrate(db, { migrationsFolder: './drizzle' });
48 replies
DTDrizzle Team
Created by wdbsb on 8/8/2023 in #help
Baseline for introspected schema
OK, here's a little progress. That initial migration starts with this: -- Current sql file was generated after introspecting the database -- If you want to run this migration please uncomment this code before executing migrations
48 replies
DTDrizzle Team
Created by wdbsb on 8/8/2023 in #help
Baseline for introspected schema
If I run the initial migration (which is commented out) I get Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/* (followed by some more commented SQL) If I delete the contents of that file before running it I get Error: Query was empty and if I un-comment the initial migration and run it it does as expected and complains that those tables already exist. BTW - I'm using MySql 8 and for this test I'm on Windows.
48 replies