Created
January 9, 2017 19:06
-
-
Save reinink/7af438bc98de72d33acf8d6c9843daf1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Select all tables from the database | |
$tables = DB::select("SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname='public'"); | |
// Get array of just the table names | |
$tables = array_column($tables, 'tablename'); | |
// Loop through and drop each table | |
// The "cascade" option is important otherwise foreign keys constraints will fail | |
foreach ($tables as $table) { | |
DB::statement('drop table '.$table.' cascade'); | |
} |
@reinink It's better to avoid using public schema for application tables as pg extensions, functions or other could overwrite something you define. Always create application schema and set search_path or for the user ALTER USER <username> SET search_path TO <appSchema>, public
to it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@decibel Hey thanks for jumping in. It seems to me that most folks user the
public
schema by default. It would be best to update this value to what is defined in the database config.