Skip to content

Add Command: Drop Database - #4657

Closed
laskoviymishka wants to merge 11 commits into
dotnet:devfrom
laskoviymishka:dropDatabaseCommand
Closed

laskoviymishka wants to merge 11 commits into
dotnet:devfrom
laskoviymishka:dropDatabaseCommand

Conversation

@laskoviymishka

Copy link
Copy Markdown
Contributor

Add new Commands: Drop Database (issue #2476)

  • Usage sample - dnx ef database delete

@divega

divega commented Feb 29, 2016

Copy link
Copy Markdown
Contributor

@bricelam your thoughts on this?

@bricelam

bricelam commented Mar 1, 2016

Copy link
Copy Markdown
Contributor

Perfect. We just need to review the command name and come up with a PowerShell counterpart.

@smitpatel

Copy link
Copy Markdown
Contributor

Should we have confirmation message to avoid deleting the database by mistake?

@laskoviymishka

Copy link
Copy Markdown
Contributor Author

@smitpatel confirmation would be good 👍 there is no fun to drop your production database accidentally 😄
I could add this feature if EF team confirm.

@laskoviymishka

Copy link
Copy Markdown
Contributor Author

Or we could allow this command only for dev enviroment. May be even remove options for changing enviroment 😄

@natemcmaster

Copy link
Copy Markdown
Contributor

+1 for adding a confirmation message, but only if we add a --force option to skip the message.

@rowanmiller

Copy link
Copy Markdown
Contributor

Agreed, confirmation and --force

If force (-f or --force) option presented skip confirm check.
@laskoviymishka

Copy link
Copy Markdown
Contributor Author

Add confirm message. If force (-f or --force) option presented skip confirm check.
I not found any confirm message like behaivior in Microsoft.Extensions.CommandLineUtils so i implemented extension method inside CommandLineApplicationExtensions

Comment thread src/dotnet-ef/DatabaseDeleteCommand.cs Outdated
Reporter.Output.WriteLine(" Cancel droping database. Use -f|--force to skip.");
return 1;
},
() => force.HasValue());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather see all of this confirmation code inline in the Execute method for now. If we need it more generally later, we can always extract it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, i think it would be nice to see such feature in DNX repo (Microsoft.Extensions.CommandLineUtils namespace) i'll create issue for them 😄

Refactor confirm implementation - move away from extensions to delete command itself.
Refactor operation executor - move drop database implementation to context operations.
using (var context = CreateContext(contextName))
{
if (confirmCheck(
$"Are you sure you want to drop the database '{context.Database.GetDbConnection().Database}' on server '{context.Database.GetDbConnection().DataSource}'? (y/N)"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this message needs to be generated by the caller (it will be different for PowerShell). Make confirmCheck take the two pieces of information instead of the message, and format them into a message in DatabaseDeleteCommand.Execute.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, I'll fix it.

@bricelam

bricelam commented Mar 7, 2016

Copy link
Copy Markdown
Contributor

Do you also want to take a stab at implementing the PowerShell command? (If not, I'll do it as part of merging you PR.)

@laskoviymishka

Copy link
Copy Markdown
Contributor Author

I could do this, where I could find power shell commands? :)

@bricelam

bricelam commented Mar 7, 2016

Copy link
Copy Markdown
Contributor

@laskoviymishka

Copy link
Copy Markdown
Contributor Author

@bricelam sorry for late response, but my knowledge of ✊ 🐚 (power shell) is not good enough to add this commands, could you please assist with these 😸

@bricelam

Copy link
Copy Markdown
Contributor

lol, no problem; I'd be happy to add it. Is this PR ready to merge then?

@laskoviymishka

Copy link
Copy Markdown
Contributor Author

@bricelam i think so, everything beside ✊ 🐚 is ready

@bricelam

Copy link
Copy Markdown
Contributor

Will be merged with #4907.

@laskoviymishka would you mind rebase-and-squashing on top of dev?

@laskoviymishka

Copy link
Copy Markdown
Contributor Author

@bricelam OK, but i do not know how to do it 😄

@bricelam

Copy link
Copy Markdown
Contributor

From command line:

git checkout dev
git pull https://github.com/aspnet/EntityFramework.git dev
git checkout dropDatabaseCommand
git rebase -i dev # change all but the first PICK to SQUASH
git push origin dropDatabaseCommand:dropDatabaseCommand --force

Or you can do it with TrotoiseGit:
image

Add [CanBeNull] attribute to fix api consistency test.

Change database property usage instead of creating new database facade object.

Fix: Script-Migrations throws when no migrations.

Undo mistake commit for different issue.

Add confirm message for dropping database.
If force (-f or --force) option presented skip confirm check.

Enhance confirm message - now it show database name and data source.
Refactor confirm implementation - move away from extensions to delete command itself.
Refactor operation executor - move drop database implementation to context operations.

Add missed virtal modifier for dropdatabase method in db context operations.

Fix incorrect message for force db delete option.
@laskoviymishka

Copy link
Copy Markdown
Contributor Author

@bricelam done, but i not sure that everything is OK 😅

@bricelam bricelam mentioned this pull request Apr 1, 2016
@bricelam

bricelam commented Apr 1, 2016

Copy link
Copy Markdown
Contributor

Merged as bd6d4f7

@bricelam bricelam closed this Apr 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants