Skip to content

Commit

Permalink
#124, #105: Use project's GUID instead of name for identification
Browse files Browse the repository at this point in the history
  • Loading branch information
seclerp committed Dec 9, 2022
1 parent 2e534f5 commit 03c2c3f
Show file tree
Hide file tree
Showing 22 changed files with 65 additions and 49 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Suggesting installing dotnet `ef command` line tools if not installed (when opening solution that contains EF Core related projects)
- Deleting used database

[Unreleased]: https://github.com/seclerp/rider-efcore/compare/v223.0.0...HEAD
[Unreleased]: https://github.com/seclerp/rider-efcore/compare/v223.1.0...HEAD
[223.1.0]: https://github.com/seclerp/rider-efcore/compare/v223.0.0...HEAD
[223.0.0]: https://github.com/seclerp/rider-efcore/compare/v222.2.0...v223.0.0
[222.2.0]: https://github.com/seclerp/rider-efcore/compare/v222.1.1...v222.2.0
Expand Down
4 changes: 2 additions & 2 deletions protocol/src/main/kotlin/model/rider/RiderEfCoreModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object RiderEfCoreModel : Ext(SolutionModel.Solution) {
}

private val MigrationsIdentity = structdef {
field("projectName", string)
field("projectId", guid)
field("dbContextClassFullName", string)
}

Expand Down Expand Up @@ -59,7 +59,7 @@ object RiderEfCoreModel : Ext(SolutionModel.Solution) {

call("hasAvailableMigrations", MigrationsIdentity, bool)
call("getAvailableMigrations", MigrationsIdentity, immutableList(MigrationInfo))
call("getAvailableDbContexts", string, immutableList(DbContextInfo))
call("getAvailableDbContexts", guid, immutableList(DbContextInfo))

callback("onMissingEfCoreToolsDetected", void, void)
}
Expand Down
16 changes: 8 additions & 8 deletions src/dotnet/Rider.Plugins.EfCore/EfCoreSolutionComponent.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Collections.Viewable;
using JetBrains.Core;
using JetBrains.Lifetimes;
using JetBrains.Platform.RdFramework.Impl;
Expand Down Expand Up @@ -185,10 +185,10 @@ private RdTask<bool> HasAvailableMigrations(Lifetime lifetime, MigrationsIdentit
{
using (ReadLockCookie.Create())
{
var project = _solution.GetProjectByName(identity.ProjectName);
var project = _solution.GetProjectByGuid(identity.ProjectId);
if (project is null)
{
return RdTask<bool>.Faulted(new ProjectNotFoundException(identity.ProjectName));
return RdTask<bool>.Faulted(new ProjectNotFoundException(identity.ProjectId));
}

var hasMigrations = _migrationsProvider.HasMigrations(project, identity.DbContextClassFullName);
Expand All @@ -201,11 +201,11 @@ private RdTask<List<MigrationInfo>> GetAvailableMigrations(Lifetime lifetime, Mi
{
using (ReadLockCookie.Create())
{
var project = _solution.GetProjectByName(identity.ProjectName);
var project = _solution.GetProjectByGuid(identity.ProjectId);

if (project is null)
{
return RdTask<List<MigrationInfo>>.Faulted(new ProjectNotFoundException(identity.ProjectName));
return RdTask<List<MigrationInfo>>.Faulted(new ProjectNotFoundException(identity.ProjectId));
}

var foundDbContexts = _migrationsProvider.GetMigrations(project, identity.DbContextClassFullName).ToList();
Expand All @@ -214,15 +214,15 @@ private RdTask<List<MigrationInfo>> GetAvailableMigrations(Lifetime lifetime, Mi
}
}

private RdTask<List<DbContextInfo>> GetAvailableDbContexts(Lifetime lifetime, string projectName)
private RdTask<List<DbContextInfo>> GetAvailableDbContexts(Lifetime lifetime, Guid projectId)
{
using (ReadLockCookie.Create())
{
var project = _solution.GetProjectByName(projectName);
var project = _solution.GetProjectByGuid(projectId);

if (project is null)
{
return RdTask<List<DbContextInfo>>.Faulted(new ProjectNotFoundException(projectName));
return RdTask<List<DbContextInfo>>.Faulted(new ProjectNotFoundException(projectId));
}

var foundDbContexts = _dbContextProvider.GetDbContexts(project).ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Rider.Plugins.EfCore.Exceptions
{
public class ProjectNotFoundException : Exception
{
public ProjectNotFoundException(string projectName) : base($"Project with name {projectName} not found")
public ProjectNotFoundException(Guid projectId) : base($"Project with ID {projectId} not found")
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import com.intellij.openapi.project.Project
import me.seclerp.rider.plugins.efcore.cli.api.models.DotnetEfVersion
import me.seclerp.rider.plugins.efcore.features.shared.BaseCommandAction
import me.seclerp.rider.plugins.efcore.rd.RiderEfCoreModel
import java.util.UUID

class DropDatabaseAction : BaseCommandAction("Database has been deleted") {
override fun createDialog(
intellijProject: Project,
toolsVersion: DotnetEfVersion,
model: RiderEfCoreModel,
currentDotnetProjectName: String?
) = DropDatabaseDialogWrapper(toolsVersion, intellijProject, currentDotnetProjectName)
currentDotnetProjectId: UUID?
) = DropDatabaseDialogWrapper(toolsVersion, intellijProject, currentDotnetProjectId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ import me.seclerp.rider.plugins.efcore.cli.api.DatabaseCommandFactory
import me.seclerp.rider.plugins.efcore.cli.api.models.DotnetEfVersion
import me.seclerp.rider.plugins.efcore.features.shared.dialog.CommonDialogWrapper
import me.seclerp.rider.plugins.efcore.features.shared.dialog.CommonDataContext
import java.util.*

class DropDatabaseDialogWrapper(
toolsVersion: DotnetEfVersion,
intellijProject: Project,
selectedProjectName: String?,
selectedProjectId: UUID?,
) : CommonDialogWrapper<CommonDataContext>(
CommonDataContext(intellijProject, false),
toolsVersion,
"Drop Database",
intellijProject,
selectedProjectName,
selectedProjectId,
false
) {
private val databaseCommandFactory = intellijProject.service<DatabaseCommandFactory>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import com.intellij.openapi.project.Project
import me.seclerp.rider.plugins.efcore.cli.api.models.DotnetEfVersion
import me.seclerp.rider.plugins.efcore.features.shared.BaseCommandAction
import me.seclerp.rider.plugins.efcore.rd.RiderEfCoreModel
import java.util.*

class UpdateDatabaseAction : BaseCommandAction("Database has been updated") {
override fun createDialog(
intellijProject: Project,
toolsVersion: DotnetEfVersion,
model: RiderEfCoreModel,
currentDotnetProjectName: String?
) = UpdateDatabaseDialogWrapper(toolsVersion, intellijProject, currentDotnetProjectName)
currentDotnetProjectId: UUID?
) = UpdateDatabaseDialogWrapper(toolsVersion, intellijProject, currentDotnetProjectId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ import me.seclerp.rider.plugins.efcore.cli.api.DatabaseCommandFactory
import me.seclerp.rider.plugins.efcore.cli.api.models.DotnetEfVersion
import me.seclerp.rider.plugins.efcore.features.shared.dialog.CommonDialogWrapper
import me.seclerp.rider.plugins.efcore.ui.*
import java.util.*

class UpdateDatabaseDialogWrapper(
toolsVersion: DotnetEfVersion,
intellijProject: Project,
selectedProjectName: String?
selectedProjectId: UUID?
) : CommonDialogWrapper<UpdateDatabaseDataContext>(
UpdateDatabaseDataContext(intellijProject),
toolsVersion,
"Update Database",
intellijProject,
selectedProjectName,
selectedProjectId,
true
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import com.intellij.openapi.project.Project
import me.seclerp.rider.plugins.efcore.cli.api.models.DotnetEfVersion
import me.seclerp.rider.plugins.efcore.features.shared.BaseCommandAction
import me.seclerp.rider.plugins.efcore.rd.RiderEfCoreModel
import java.util.*

class ScaffoldDbContextAction : BaseCommandAction("DbContext has been scaffolded") {
override fun createDialog(
intellijProject: Project,
toolsVersion: DotnetEfVersion,
model: RiderEfCoreModel,
currentDotnetProjectName: String?
) = ScaffoldDbContextDialogWrapper(toolsVersion, intellijProject, currentDotnetProjectName)
currentDotnetProjectId: UUID?
) = ScaffoldDbContextDialogWrapper(toolsVersion, intellijProject, currentDotnetProjectId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,20 @@ import me.seclerp.observables.ui.dsl.bindSelected
import me.seclerp.observables.ui.dsl.bindText
import me.seclerp.rider.plugins.efcore.ui.textFieldForRelativeFolder
import java.io.File
import java.util.*
import javax.swing.JComponent

@Suppress("UnstableApiUsage")
class ScaffoldDbContextDialogWrapper(
toolsVersion: DotnetEfVersion,
intellijProject: Project,
selectedProjectName: String?,
selectedProjectId: UUID?,
) : CommonDialogWrapper<ScaffoldDbContextDataContext>(
ScaffoldDbContextDataContext(intellijProject),
toolsVersion,
"Scaffold DbContext",
intellijProject,
selectedProjectName,
selectedProjectId,
requireMigrationsInProject = false
) {
val dbContextCommandFactory = intellijProject.service<DbContextCommandFactory>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import com.intellij.openapi.project.Project
import me.seclerp.rider.plugins.efcore.cli.api.models.DotnetEfVersion
import me.seclerp.rider.plugins.efcore.features.shared.BaseCommandAction
import me.seclerp.rider.plugins.efcore.rd.RiderEfCoreModel
import java.util.*

class AddMigrationAction : BaseCommandAction("New migration has been created") {
override fun createDialog(
intellijProject: Project,
toolsVersion: DotnetEfVersion,
model: RiderEfCoreModel,
currentDotnetProjectName: String?
) = AddMigrationDialogWrapper(toolsVersion, intellijProject, currentDotnetProjectName)
currentDotnetProjectId: UUID?
) = AddMigrationDialogWrapper(toolsVersion, intellijProject, currentDotnetProjectId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ import me.seclerp.observables.ui.dsl.bindText
import me.seclerp.rider.plugins.efcore.ui.AnyInputDocumentListener
import me.seclerp.rider.plugins.efcore.ui.textFieldForRelativeFolder
import java.io.File
import java.util.UUID

class AddMigrationDialogWrapper(
toolsVersion: DotnetEfVersion,
intellijProject: Project,
selectedProjectName: String?,
selectedProjectId: UUID?,
) : CommonDialogWrapper<AddMigrationDataContext>(
AddMigrationDataContext(intellijProject),
toolsVersion,
"Add Migration",
intellijProject,
selectedProjectName
selectedProjectId
) {
val migrationsCommandFactory = intellijProject.service<MigrationsCommandFactory>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import com.intellij.openapi.project.Project
import me.seclerp.rider.plugins.efcore.cli.api.models.DotnetEfVersion
import me.seclerp.rider.plugins.efcore.features.shared.BaseCommandAction
import me.seclerp.rider.plugins.efcore.rd.RiderEfCoreModel
import java.util.*

class RemoveLastMigrationAction : BaseCommandAction("Last migration has been removed") {
override fun createDialog(
intellijProject: Project,
toolsVersion: DotnetEfVersion,
model: RiderEfCoreModel,
currentDotnetProjectName: String?
) = RemoveLastMigrationDialogWrapper(toolsVersion, intellijProject, currentDotnetProjectName)
currentDotnetProjectId: UUID?
) = RemoveLastMigrationDialogWrapper(toolsVersion, intellijProject, currentDotnetProjectId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ import me.seclerp.rider.plugins.efcore.cli.api.MigrationsCommandFactory
import me.seclerp.rider.plugins.efcore.cli.api.models.DotnetEfVersion
import me.seclerp.rider.plugins.efcore.cli.execution.CliCommandResult
import me.seclerp.rider.plugins.efcore.features.shared.dialog.CommonDialogWrapper
import java.util.*

class RemoveLastMigrationDialogWrapper(
toolsVersion: DotnetEfVersion,
intellijProject: Project,
selectedProjectName: String?,
selectedProjectId: UUID?,
) : CommonDialogWrapper<RemoveLastMigrationDataContext>(
RemoveLastMigrationDataContext(intellijProject),
toolsVersion,
"Remove Last Migration",
intellijProject,
selectedProjectName,
selectedProjectId,
true
) {
val migrationsCommandFactory = intellijProject.service<MigrationsCommandFactory>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package me.seclerp.rider.plugins.efcore.features.migrations.script
import com.intellij.openapi.project.Project
import me.seclerp.rider.plugins.efcore.cli.api.models.DotnetEfVersion
import me.seclerp.rider.plugins.efcore.features.shared.BaseCommandAction
import me.seclerp.rider.plugins.efcore.features.shared.dialog.CommonDialogWrapper
import me.seclerp.rider.plugins.efcore.rd.RiderEfCoreModel
import java.util.*

class GenerateScriptAction : BaseCommandAction("Script has been generated") {
override fun createDialog(
intellijProject: Project,
toolsVersion: DotnetEfVersion,
model: RiderEfCoreModel,
currentDotnetProjectName: String?
) = GenerateScriptDialogWrapper(toolsVersion, intellijProject, currentDotnetProjectName)
currentDotnetProjectId: UUID?
) = GenerateScriptDialogWrapper(toolsVersion, intellijProject, currentDotnetProjectId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ import me.seclerp.rider.plugins.efcore.cli.api.MigrationsCommandFactory
import me.seclerp.rider.plugins.efcore.cli.api.models.DotnetEfVersion
import me.seclerp.rider.plugins.efcore.features.shared.dialog.CommonDialogWrapper
import me.seclerp.rider.plugins.efcore.ui.items.MigrationItem
import java.util.*

class GenerateScriptDialogWrapper(
toolsVersion: DotnetEfVersion,
intellijProject: Project,
selectedProjectName: String?
selectedProjectId: UUID?
) : CommonDialogWrapper<GenerateScriptDataContext>(
GenerateScriptDataContext(intellijProject),
toolsVersion,
"Generate SQL Script",
intellijProject,
selectedProjectName,
selectedProjectId,
requireMigrationsInProject = true
) {
val migrationsCommandFactory = intellijProject.service<MigrationsCommandFactory>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.jetbrains.rider.model.RdProjectDescriptor
import com.jetbrains.rider.model.RdUnloadProjectDescriptor
import com.jetbrains.rider.projectView.workspace.ProjectModelEntity
import com.jetbrains.rider.projectView.workspace.getProjectModelEntities
import java.util.*

fun AnActionEvent.isEfCoreActionContext(): Boolean {
if (project == null) return false
Expand All @@ -29,10 +30,12 @@ fun AnActionEvent.isEfCoreActionContext(): Boolean {
return true
}

fun AnActionEvent.getDotnetProjectName(): String? {
val actionFile = getData(PlatformDataKeys.VIRTUAL_FILE) ?: return ""
fun AnActionEvent.getDotnetProjectId(): UUID? {
val actionFile = getData(PlatformDataKeys.VIRTUAL_FILE) ?: return null

return getFileProject(project!!, actionFile)?.descriptor?.name
return getFileProject(project!!, actionFile)?.descriptor?.let {
(it as RdProjectDescriptor).originalGuid
}
}

@Suppress("UnstableApiUsage")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import me.seclerp.rider.plugins.efcore.cli.execution.PreferredCommandExecutorPro
import me.seclerp.rider.plugins.efcore.features.eftools.InstallDotnetEfAction
import me.seclerp.rider.plugins.efcore.features.shared.dialog.BaseDialogWrapper
import me.seclerp.rider.plugins.efcore.rd.ToolKind
import java.util.UUID

abstract class BaseCommandAction(
private val actionPerformedText: String
Expand Down Expand Up @@ -53,12 +54,12 @@ abstract class BaseCommandAction(
intellijProject: Project,
toolsVersion: DotnetEfVersion,
model: RiderEfCoreModel,
currentDotnetProjectName: String?): BaseDialogWrapper
currentDotnetProjectId: UUID?): BaseDialogWrapper

private fun openDialog(actionEvent: AnActionEvent, efCoreVersion: DotnetEfVersion) {
val intellijProject = actionEvent.project!!
val model = getEfCoreRiderModel(actionEvent)
val currentDotnetProjectName = actionEvent.getDotnetProjectName()
val currentDotnetProjectName = actionEvent.getDotnetProjectId()
val dialog = createDialog(intellijProject, efCoreVersion, model, currentDotnetProjectName)

if (dialog.showAndGet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class ObservableMigrations(
fun initBinding() {
this.bind(dbContext) {
if (it != null) {
val migrationsProjectName = migrationsProject.value!!.name
val migrationsProjectId = migrationsProject.value!!.id
val dbContextName = it.fullName
val migrations = intellijProject.solution.riderEfCoreModel.getAvailableMigrations.runUnderProgress(
MigrationsIdentity(migrationsProjectName, dbContextName), intellijProject, "Loading available migrations...",
MigrationsIdentity(migrationsProjectId, dbContextName), intellijProject, "Loading available migrations...",
isCancelable = true,
throwFault = true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ open class CommonDataContext(
if (requireDbContext) {
availableDbContexts.bind(migrationsProject) {
beModel.getAvailableDbContexts.runUnderProgress(
it!!.name, intellijProject, "Loading DbContext classes...",
it!!.id, intellijProject, "Loading DbContext classes...",
isCancelable = true,
throwFault = true
)?.toMutableList() ?: mutableListOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CommonDialogValidator(
null
else {
val migrationsIdentity = MigrationsIdentity(
it.item.displayName,
it.item.data.id,
dataCtx.dbContext.value!!.fullName)

val hasMigrations = beModel.hasAvailableMigrations.runUnderProgress(
Expand Down
Loading

0 comments on commit 03c2c3f

Please sign in to comment.