Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add TimescaleDB hypertable support to PostgresBuilder::dropAllTables()#56280

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
designgears wants to merge4 commits intolaravel:12.x
base:12.x
Choose a base branch
Loading
fromdesigngears:12.x

Conversation

designgears
Copy link

Description

This change enhances the PostgreSQL schema builder to properly handle TimescaleDB hypertables when dropping all tables from the database.

Problem

When usingphp artisan migrate:fresh or callingdropAllTables() on databases with TimescaleDB hypertables, the operation fails because hypertables require special handling and cannot be dropped using standard batchDROP TABLE operations. This results in migration errors and prevents developers from refreshing their database schema during development.

Solution

  • TimescaleDB Detection: Added detection for the TimescaleDB extension usingpg_extension before attempting hypertable operations
  • Hypertable Identification: Querytimescaledb_information.hypertables to identify existing hypertables using correct column names (hypertable_schema andhypertable_name)
  • Separate Handling: Drop hypertables individually withCASCADE option before processing regular tables
  • Graceful Fallback: When TimescaleDB extension is not installed, the method continues with standard table dropping behavior

Benefits to End Users

  1. Seamless Development Workflow: Developers using TimescaleDB can now usephp artisan migrate:fresh without manual intervention
  2. Zero Breaking Changes: Maintains full backward compatibility with standard PostgreSQL databases
  3. Automatic Detection: No configuration required - automatically detects and handles TimescaleDB when present
  4. Error Prevention: Eliminates common migration failures in TimescaleDB environments

Code Changes

Modified Files

  • src/Illuminate/Database/Schema/PostgresBuilder.php

Key Changes

// Added TimescaleDB extension detection$hasTimescaleDB = !empty($this->connection->select("SELECT 1 FROM pg_extension WHERE extname = 'timescaledb'"));// Query hypertables with correct column namesif ($hasTimescaleDB) {$hypertables =$this->connection->select("SELECT hypertable_schema || '.' || hypertable_name as name FROM timescaledb_information.hypertables"    );$hypertables =array_column($hypertables,'name');}// Drop hypertables individually with CASCADEif (in_array($table['schema_qualified_name'],$hypertables)) {$this->connection->statement("DROP TABLE IF EXISTS{$table['schema_qualified_name']} CASCADE");}

Compatibility

  • PostgreSQL: 9.6+ (existing requirement)
  • TimescaleDB: Optional extension support
  • Laravel: No breaking changes to existing API
  • PHP: Follows existing Laravel requirements

This change enhances the PostgreSQL schema builder to properly handle TimescaleDB hypertables when dropping all tables from the database.
@GrahamCampbell
Copy link
Member

GrahamCampbell commentedJul 13, 2025
edited
Loading

This seems like a kinda edge use case.It's a slippery slope to try and support every database that uses the PostgreSQL wire protocol, with varying degrees of actually being compatible. EDIT: Oh, I see this is an extension, and not a separate database... still the use case is kinda fringe.

@designgears
Copy link
Author

This seems like a kinda edge use case.It's a slippery slope to try and support every database that uses the PostgreSQL wire protocol, with varying degrees of actually being compatible. EDIT: Oh, I see this is an extension, and not a separate database... still the use case is kinda fringe.

I'll leave this here either way, I did find a package that fills in a lot of the missing pgsql functionality.
laravel-postgresql-enhanced

@taylorotwell
Copy link
Member

Tests fail.

@taylorotwelltaylorotwell marked this pull request as draftJuly 18, 2025 16:15
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@designgears@GrahamCampbell@taylorotwell

[8]ページ先頭

©2009-2025 Movatter.jp