Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add drop database support for PostgreSQL #6

Open
knunery opened this issue May 21, 2020 · 7 comments
Open

Add drop database support for PostgreSQL #6

knunery opened this issue May 21, 2020 · 7 comments
Labels
enhancement New feature or request

Comments

@knunery
Copy link

knunery commented May 21, 2020

I would like to make a PR to add drop database support for PostgreSQL. Should I go ahead and make a PR for this @AdrianJSClark @droyad ?

@knunery knunery added the enhancement New feature or request label May 21, 2020
@droyad
Copy link
Member

droyad commented Jun 17, 2020

Yes please

@mariusingjer
Copy link

Will we are waiting for the drop, you can do something like this in the meantime:

    public static void DropDatabase(string connectionString)
    {
        var builder = new NpgsqlConnectionStringBuilder(connectionString);

        var databaseName = builder.Database;
        builder.Database = "postgres";

        using (var connection = new NpgsqlConnection(builder.ToString()))
        {
            connection.Open();

            using (var command = new NpgsqlCommand($"SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = \'{databaseName}\'; DROP DATABASE IF EXISTS \"{databaseName}\"", connection))
            {
                command.ExecuteNonQuery();
            }

            connection.Close();
            Console.WriteLine("Dropped database {0}", databaseName);
        }
    }

@dncnkrs
Copy link

dncnkrs commented Nov 7, 2020

Given there hasn't been any movement here lately, and this feature would make some of my current projects easier, I'm currently working on this issue.

@MollsAndHersh
Copy link

What about using context.Database.EnsureDeleted()? Works like a charm for me.

@dncnkrs
Copy link

dncnkrs commented Apr 5, 2021

@MollsAndHersh Unfortunately EnsureDeleted Is an EF method, which not all projects will use.

@Obish
Copy link

Obish commented Jun 25, 2021

@dncnkrs any luck with this feature?

@flatrick
Copy link

@Obish there has been a PR for this since 2020-11-07 (see PR 538).

@droyad is there anyway we can help with getting this issue/PR finished?
Looking around at issues and PRs, I get the feeling that this project is on the backburner for the project-owners, are you possibly interested in new blood to assist?

@droyad droyad transferred this issue from DbUp/DbUp Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: v6
Development

No branches or pull requests

7 participants