adonisjs / lucid

AdonisJS SQL ORM. Supports PostgreSQL, MySQL, MSSQL, Redshift, SQLite and many more
https://lucid.adonisjs.com/
MIT License
1.09k stars 195 forks source link

refactor: change sqlite dropAllTables implementation #1001

Closed Julien-R44 closed 9 months ago

Julien-R44 commented 9 months ago

❓ Type of change

📚 Description

Fix https://github.com/adonisjs/lucid/issues/999

I have updated the implementation of dropAllTables for better-sqlite3 and sqlite :

As a result, I've decided to drop all tables with multiples queries rather than modifying sqlite_master directly. this way, we don't need to activate the unsafe mode. the method is probably slower, but imo it doesn't matter at all

indexes and triggers are automatically deleted if linked to a deleted table

RomainLanz commented 9 months ago

LGTM

thetutlage commented 9 months ago

I did not read much about it. Does SQLite has such thing called FOREIGN_KEY_CHECKS, which might stop from dropping tables?

This is our implementation for MYSQL https://github.com/adonisjs/lucid/blob/f84a710c192228b3147e3b93369da46a60cded5c/src/dialects/mysql.ts

thetutlage commented 9 months ago

This is what Laravel does. They call compileEnableWriteableSchema, then drops the tables and then turns it off via compileDisableWriteableSchema.

https://github.com/laravel/framework/blob/10.x/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php#L543-L556

https://github.com/laravel/framework/blob/10.x/src/Illuminate/Database/Schema/SQLiteBuilder.php#L87

Julien-R44 commented 9 months ago

should be all good now