Skip to content

Improve progress & remove multiple migrations #32

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

Merged
merged 2 commits into from
Jan 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"contributes": {
"commands": [
{
"command": "entityframework.removeMigration",
"command": "entityframework.removeMigrations",
"title": "Remove Migration",
"icon": {
"light": "icons/trash_light.svg",
Expand Down Expand Up @@ -130,7 +130,7 @@
"when": "false"
},
{
"command": "entityframework.removeMigration",
"command": "entityframework.removeMigrations",
"when": "false"
},
{
Expand Down Expand Up @@ -171,12 +171,12 @@
],
"view/item/context": [
{
"command": "entityframework.removeMigration",
"command": "entityframework.removeMigrations",
"when": "viewItem =~ /^migration-.*\\|?can-remove\\|?.*$/",
"group": "inline@1"
},
{
"command": "entityframework.removeMigration",
"command": "entityframework.removeMigrations",
"when": "viewItem =~ /^migration-.*\\|?can-remove\\|?.*$/",
"group": "context@2"
},
Expand All @@ -203,22 +203,22 @@
{
"command": "entityframework.addMigration",
"when": "viewItem == dbContext",
"group": "context@4"
"group": "inline@4"
},
{
"command": "entityframework.addMigration",
"when": "viewItem == dbContext",
"group": "inline@4"
"group": "context@1"
},
{
"command": "entityframework.generateScript",
"when": "viewItem == dbContext",
"group": "context@3"
"group": "inline@3"
},
{
"command": "entityframework.generateScript",
"when": "viewItem == dbContext",
"group": "inline@3"
"group": "context@2"
},
{
"command": "entityframework.generateERD",
Expand All @@ -228,7 +228,7 @@
{
"command": "entityframework.generateERD",
"when": "viewItem == dbContext",
"group": "context@2"
"group": "context@3"
},
{
"command": "entityframework.dbContextInfo",
Expand All @@ -238,7 +238,7 @@
{
"command": "entityframework.dbContextInfo",
"when": "viewItem == dbContext",
"group": "context@1"
"group": "context@4"
},
{
"command": "entityframework.scaffold",
Expand Down
14 changes: 11 additions & 3 deletions src/actions/AddMigrationAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as vscode from 'vscode';
import { CommandProvider } from '../commands/CommandProvider';
import { RefreshTreeCommand } from '../commands/RefreshTreeCommand';
import { getCommandsConfig } from '../config/config';
import { TREE_VIEW_ID } from '../constants/constants';

import type { TerminalProvider } from '../terminal/TerminalProvider';
import {
Expand Down Expand Up @@ -40,13 +41,20 @@ export class AddMigrationAction extends TerminalAction {
return vscode.window.withProgress(
{
title: 'Adding Migration...',
location: vscode.ProgressLocation.Window,
location: { viewId: TREE_VIEW_ID },
cancellable: true,
},
async () => {
const output = await super.run({
async (_progress, cancellationToken) => {
cancellationToken.onCancellationRequested(() => {
this.cancel();
});

await this.start({
...this.params,
migrationName,
});

const output = await this.getOutput();
const cacheId = DbContextTreeItem.getCacheId(
this.workspaceRoot,
this.project,
Expand Down
21 changes: 13 additions & 8 deletions src/actions/DBContextInfoCommandAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as vscode from 'vscode';

import { CLI } from '../cli/CLI';
import { getCommandsConfig } from '../config/config';
import { TREE_VIEW_ID } from '../constants/constants';

import type { TerminalProvider } from '../terminal/TerminalProvider';
import { TextDocumentProvider } from '../util/TextDocumentProvider';
Expand Down Expand Up @@ -29,15 +30,19 @@ export class DBContextInfoCommandAction extends TerminalAction {
return vscode.window.withProgress(
{
title: 'Getting DbContext Info...',
location: vscode.ProgressLocation.Window,
location: { viewId: TREE_VIEW_ID },
cancellable: true,
},
async () => {
const output = CLI.getDataFromStdOut(
await super.run(undefined, {
removeDataFromOutput: true,
asJson: true,
}),
);
async (_progress, cancellationToken) => {
cancellationToken.onCancellationRequested(() => {
this.cancel();
});

await this.start(undefined, {
removeDataFromOutput: true,
asJson: true,
});
const output = CLI.getDataFromStdOut(await this.getOutput());
const uri = vscode.Uri.parse(
`${TextDocumentProvider.scheme}:${output}`,
);
Expand Down
40 changes: 21 additions & 19 deletions src/actions/GenerateERDAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import util from 'util';
import { CLI } from '../cli/CLI';
import { getCommandsConfig, getERDConfig } from '../config/config';
import { TerminalAction } from './TerminalAction';
import { DEFAULT_EFCORE_PROVIDERS } from '../constants/constants';
import { DEFAULT_EFCORE_PROVIDERS, TREE_VIEW_ID } from '../constants/constants';
import { InputWizard } from '../util/InputWizard';
import { ERDiagramWebViewProvider } from '../util/ERDiagramWebViewProvider';
import { ProjectFilesProvider } from '../solution/ProjectFilesProvider';
Expand Down Expand Up @@ -130,9 +130,13 @@ export class GenerateERDAction extends TerminalAction {
return vscode.window.withProgress(
{
title: 'Generating diagram...',
location: vscode.ProgressLocation.Window,
location: { viewId: TREE_VIEW_ID },
cancellable: true,
},
async () => {
async (_progress, cancellationToken) => {
cancellationToken.onCancellationRequested(() => {
this.cancel();
});
try {
// Backup any existing DbContext template
const finalTemplatePathExists = fs.existsSync(finalTemplatePath);
Expand All @@ -145,23 +149,21 @@ export class GenerateERDAction extends TerminalAction {
finalConfigPath,
JSON.stringify(erDiagramConfig, null, 2),
);

const output = CLI.getDataFromStdOut(
await super.run(
{
...this.params,
connectionString,
provider,
outputDir: this.outputDir,
},
{
asJson: true,
removeDataFromOutput: true,
},
),
await this.start(
{
...this.params,
connectionString,
provider,
outputDir: this.outputDir,
},
{
asJson: true,
removeDataFromOutput: true,
},
);

const result = JSON.parse(output) as ScaffoldResult;
const output = await this.getOutput();
const data = CLI.getDataFromStdOut(await this.getOutput());
const result = JSON.parse(data) as ScaffoldResult;

const fileContents = fs.readFileSync(result.contextFile, 'utf-8');

Expand Down
25 changes: 14 additions & 11 deletions src/actions/GenerateScriptAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as vscode from 'vscode';

import { CLI } from '../cli/CLI';
import { getCommandsConfig } from '../config/config';
import { TREE_VIEW_ID } from '../constants/constants';
import type { TerminalProvider } from '../terminal/TerminalProvider';
import { TextDocumentProvider } from '../util/TextDocumentProvider';
import { TerminalAction } from './TerminalAction';
Expand All @@ -28,21 +29,23 @@ export class GenerateScriptAction extends TerminalAction {
return vscode.window.withProgress(
{
title: 'Generating script...',
location: vscode.ProgressLocation.Window,
location: { viewId: TREE_VIEW_ID },
cancellable: true,
},
async () => {
const output = CLI.getDataFromStdOut(
await super.run(undefined, {
removeDataFromOutput: true,
}),
);
const uri = vscode.Uri.parse(
`${TextDocumentProvider.scheme}:${output}`,
);
async (_progress, cancellationToken) => {
cancellationToken.onCancellationRequested(() => {
this.cancel();
});
await this.start(undefined, {
removeDataFromOutput: true,
});
const output = await this.getOutput();
const data = CLI.getDataFromStdOut(output);
const uri = vscode.Uri.parse(`${TextDocumentProvider.scheme}:${data}`);
const doc = await vscode.workspace.openTextDocument(uri);
await vscode.languages.setTextDocumentLanguage(doc, 'sql');
await vscode.window.showTextDocument(doc, { preview: false });
return output;
return data;
},
);
}
Expand Down
24 changes: 17 additions & 7 deletions src/actions/RemoveMigrationAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as vscode from 'vscode';
import { CommandProvider } from '../commands/CommandProvider';
import { RefreshTreeCommand } from '../commands/RefreshTreeCommand';
import { getCommandsConfig } from '../config/config';
import { TREE_VIEW_ID } from '../constants/constants';
import type { TerminalProvider } from '../terminal/TerminalProvider';
import {
dbContextsCache,
Expand All @@ -15,6 +16,7 @@ export class RemoveMigrationAction extends TerminalAction {
private readonly workspaceRoot: string,
private readonly dbContext: string,
private readonly project: string,
private readonly refresh?: boolean,
) {
super(
terminalProvider,
Expand All @@ -31,20 +33,28 @@ export class RemoveMigrationAction extends TerminalAction {
return vscode.window.withProgress(
{
title: 'Removing Migration...',
location: vscode.ProgressLocation.Window,
location: { viewId: TREE_VIEW_ID },
cancellable: true,
},
async () => {
const output = await super.run();
async (_progress, cancellationToken) => {
cancellationToken.onCancellationRequested(() => {
this.cancel();
});
await this.start();
const output = await this.getOutput();
const cacheId = DbContextTreeItem.getCacheId(
this.workspaceRoot,
this.project,
this.dbContext,
);
dbContextsCache.clear(cacheId);
await vscode.commands.executeCommand(
CommandProvider.getCommandName(RefreshTreeCommand.commandName),
false,
);
const refresh = this.refresh || this.refresh === undefined;
if (refresh) {
await vscode.commands.executeCommand(
CommandProvider.getCommandName(RefreshTreeCommand.commandName),
false,
);
}
return output;
},
);
Expand Down
35 changes: 35 additions & 0 deletions src/actions/RemoveMigrationsAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as vscode from 'vscode';
import { CommandProvider } from '../commands/CommandProvider';
import { RefreshTreeCommand } from '../commands/RefreshTreeCommand';
import type { TerminalProvider } from '../terminal/TerminalProvider';
import type { MigrationTreeItem } from '../treeView/MigrationTreeItem';
import type { IAction } from './IAction';
import { RemoveMigrationAction } from './RemoveMigrationAction';

export class RemoveMigrationsAction implements IAction {
constructor(
private readonly terminalProvider: TerminalProvider,
private readonly workspaceRoot: string,
private readonly dbContext: string,
private readonly project: string,
private readonly migrationsToRemove: MigrationTreeItem[],
) {}

public async run() {
for (let i = 0; i < this.migrationsToRemove.length; i++) {
await new RemoveMigrationAction(
this.terminalProvider,
this.workspaceRoot,
this.dbContext,
this.project,
false,
).run();
}
if (this.migrationsToRemove.length > 0) {
await vscode.commands.executeCommand(
CommandProvider.getCommandName(RefreshTreeCommand.commandName),
false,
);
}
}
}
12 changes: 9 additions & 3 deletions src/actions/RunMigrationAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as vscode from 'vscode';
import { CommandProvider } from '../commands/CommandProvider';
import { RefreshTreeCommand } from '../commands/RefreshTreeCommand';
import { getCommandsConfig } from '../config/config';
import { TREE_VIEW_ID } from '../constants/constants';
import type { TerminalProvider } from '../terminal/TerminalProvider';
import {
dbContextsCache,
Expand Down Expand Up @@ -33,10 +34,15 @@ export class RunMigrationAction extends TerminalAction {
return vscode.window.withProgress(
{
title: 'Running Migration...',
location: vscode.ProgressLocation.Window,
location: { viewId: TREE_VIEW_ID },
cancellable: true,
},
async () => {
const output = await super.run();
async (_progress, cancellationToken) => {
cancellationToken.onCancellationRequested(() => {
this.cancel();
});
await this.start();
const output = await this.getOutput();

const cacheId = DbContextTreeItem.getCacheId(
this.workspaceRoot,
Expand Down
Loading