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

[bug] Persistent Tasks and Dependencies #1365

Open
rawkode opened this issue Mar 4, 2024 · 1 comment
Open

[bug] Persistent Tasks and Dependencies #1365

rawkode opened this issue Mar 4, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@rawkode
Copy link

rawkode commented Mar 4, 2024

Describe the bug

It's my understanding from the docs that persistent tasks are always run last, and kept running.

I'm curious how we should handle cases where we need to apply migrations to a database that needs to be running?

I've included my setup below, which runs turso dev to get us a libsql database running. Once it's running, I want to apply the migrations and run grafbase; also a persistent task.

Steps to reproduce

# yaml-language-server: $schema=https://moonrepo.dev/schemas/project.json

# We should add a global flake
# to set MOON_TOOLCHAIN_FORCE_GLOBALS=true
type: application
platform: "system"

project:
  name: shows-service
  description: Microservice for Show Management

tasks:
  install-dependencies:
    command: bun install
    inputs:
      - ./bun.lockb
      - ./package.json
    outputs:
      - ./node_modules

  dev-grafbase:
    deps:
      - install-dependencies
    command: bun x grafbase dev
    options:
      persistent: true

  dev-turso:
    command: turso
    args:
      - dev
      - --port
      - "4021"
    options:
      persistent: true

  dev-turso-generate-migrations:
    deps:
      - install-dependencies
    inputs:
      - ./drizzle/schema
    command: cd drizzle && bunx drizzle-kit generate:sqlite

  dev-turso-apply-migrations:
    deps:
      - dev-turso-generate-migrations
    inputs:
      - ./drizzle/migrations
      - ./drizzle/migrate.ts
    command: cd drizzle && bun migrate.ts

  dev-turso-seed:
    deps:
      - dev-turso-apply-migrations
    inputs:
      - ./drizzle/seed.ts
    command: cd drizzle && bun seed.ts

  dev:
    local: true
    deps:
      - install-dependencies
      - dev-turso
      - dev-grafbase
      - dev-turso-seed
@rawkode rawkode added the bug Something isn't working label Mar 4, 2024
@milesj
Copy link
Collaborator

milesj commented Mar 4, 2024

@rawkode Yeah, this is kind of a tricky one. I honestly don't think this is possible with moon directly at the moment, since all persistent tasks are batched together. You may have to wrap the migration part in a bash/js script that waits to execute until the DB is online, and then update the moon task to execute the script.

On a side note, you shouldn't need install-dependencies since moon does that automatically. https://moonrepo.dev/docs/how-it-works/action-graph#install-dependencies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants