Skip to content

Conversation

@Unbreathable
Copy link
Contributor

No description provided.

- Services are now actually managed by the runner
- Renamed postgres driver to postgres_legacy (and separated it into more
  files)
- EnvironmentValue support for the Postgres Driver
- Implemented the new instruction layer into the Runner
@Unbreathable Unbreathable marked this pull request as draft February 8, 2026 17:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors Magic’s container management from a database-specific model to a generic service driver model, updating plan generation/deployment and introducing a legacy PostgreSQL service driver implementation.

Changes:

  • Introduces mconfig.ServiceDriver + registry and migrates planning to Plan.Containers keyed by driver unique IDs.
  • Reworks deployment to pull/start/health-check/initialize service containers (concurrently) and adds runtime instructions (clear/drop tables).
  • Removes the old integration/* helpers and the legacy mconfig/databases.go database abstraction; updates example project usage accordingly.

Reviewed changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
util/util.go Adds random port selection + port scan helper used during planning.
mrunner/runner_plan.go Replaces DB planning with service-driver container + port allocation planning.
mrunner/runner_deploy.go Replaces DB deployment with generic service container pull/start/health/initialize + instruction dispatch.
mrunner/runner.go Runner now tracks service drivers and updates Docker client initialization.
mrunner/databases/postgres_legacy.go Adds legacy Postgres driver (v14–17) and env helpers for host/port/user/pass.
mrunner/databases/postgres_legacy_container.go Implements container create/health/initialize for legacy Postgres driver.
mrunner/databases/postgres_legacy_instruct.go Implements “clear tables” / “drop tables” instructions for legacy Postgres.
mrunner/databases/init.go Registers the Postgres driver in the global driver registry.
mconfig/services.go Adds ServiceDriver interface, instruction types, container allocation/info structs, and registry helpers.
mconfig/plan.go Replaces DB-type plan with Containers map + generic container naming helpers.
mconfig/environment.go Adds ValueFunction helper for dynamic environment values.
mconfig/databases.go Removes legacy database abstraction layer.
mconfig/context.go Context now tracks services (drivers) and project directory; removes DB APIs.
integration/sanitize_path.go Removed legacy integration helper.
integration/port_scanner.go Removed legacy integration helper (port scanning moved to util).
integration/path_evaluator_test.go Removed legacy integration test file.
integration/path_evaluator.go Removed legacy integration helper.
integration/formatting.go Removed legacy integration helper.
integration/file.go Removed legacy integration helper.
integration/execute_command.go Removed legacy integration helper.
integration/directory.go Removed legacy integration helper.
integration/constants.go Removed legacy integration constant.
initializer.go Updates context creation to include project directory.
factory.go Updates plan filename format and adjusts project dir discovery loop.
examples/real-project/starter/start_test.go Updates test helper to use ClearTables() API.
examples/real-project/starter/scripts_database.go Adds clear vs reset scripts using new instruction APIs.
examples/real-project/starter/config.go Updates example to register Postgres service driver and use driver env helpers.
Comments suppressed due to low confidence (2)

mrunner/runner_deploy.go:259

  • If ContainerInspect fails, the code still accesses containerInfo.Container.Mounts. When err != nil, containerInfo.Container can be nil, causing a panic. Guard mount/volume extraction behind if err == nil && containerInfo.Container != nil, or return the inspect error before using the response.
		// Get all the attached volumes to delete them manually
		containerInfo, err := r.client.ContainerInspect(ctx, containerID, client.ContainerInspectOptions{})
		if err != nil {
			util.Log.Println("Warning: Couldn't inspect container:", err)
		}
		var volumeNames []string
		if containerInfo.Container.Mounts != nil {
			for _, mnt := range containerInfo.Container.Mounts {
				if mnt.Type == mount.TypeVolume && mnt.Name != "" {
					volumeNames = append(volumeNames, mnt.Name)
				}

mrunner/runner_plan.go:67

  • In the host port allocation loop, slices.Contains(portsToAllocate, port) is always true for the current port (since you're iterating over portsToAllocate). That means the condition effectively only checks !util.ScanPort(toAllocate) and never ensures toAllocate isn’t already reserved elsewhere in portsToAllocate. This can yield duplicate allocations. Use slices.Contains(portsToAllocate, toAllocate) (or a set) and treat ScanPort + uniqueness as separate constraints.
	if len(portsToAllocate) >= 0 {
		for _, port := range portsToAllocate {

			// Generate a new port in case the current one is taken
			toAllocate := port
			for slices.Contains(portsToAllocate, port) && !util.ScanPort(toAllocate) {
				toAllocate = util.RandomPort(DefaultStartPort, DefaultEndPort)
			}

			// Add the port to the plan
			allocatedPorts[port] = toAllocate
		}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

1 participant