Skip to content

Commit ddf8374

Browse files
committed
fixes getTables for sqlite.
1 parent e120879 commit ddf8374

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

src/Mvc/Database/SchemaExporter.php

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,34 @@ private function getLatestMigrationVersion(): ?string
121121
*/
122122
private function getTables(): array
123123
{
124-
// Get all tables using adapter's native method
125-
$tables = $this->_Adapter->getTables();
124+
$adapterType = $this->_Adapter->getAdapterType();
126125

127-
// Return array of table names
128-
return array_map( function( $table ) {
129-
return $table->getName();
130-
}, $tables );
126+
switch( $adapterType )
127+
{
128+
case 'mysql':
129+
$sql = "SELECT TABLE_NAME FROM information_schema.TABLES
130+
WHERE TABLE_SCHEMA = ? AND TABLE_TYPE = 'BASE TABLE'
131+
ORDER BY TABLE_NAME";
132+
$rows = $this->_Adapter->fetchAll( $sql, [$this->_Adapter->getOption( 'name' )] );
133+
return array_column( $rows, 'TABLE_NAME' );
134+
135+
case 'pgsql':
136+
$sql = "SELECT tablename FROM pg_catalog.pg_tables
137+
WHERE schemaname = 'public'
138+
ORDER BY tablename";
139+
$rows = $this->_Adapter->fetchAll( $sql );
140+
return array_column( $rows, 'tablename' );
141+
142+
case 'sqlite':
143+
$sql = "SELECT name FROM sqlite_master
144+
WHERE type = 'table' AND name NOT LIKE 'sqlite_%'
145+
ORDER BY name";
146+
$rows = $this->_Adapter->fetchAll( $sql );
147+
return array_column( $rows, 'name' );
148+
149+
default:
150+
throw new \RuntimeException( "Unsupported adapter type: {$adapterType}" );
151+
}
131152
}
132153

133154
/**

0 commit comments

Comments
 (0)