Commit a23c0fb2 authored by moha-s's avatar moha-s
Browse files

[New Job] - Composer_migrate - initial version

parent 495edbef
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
## Objective

This job will allow you to migrate the database using a migration file that you already have in `database/migrations`, and it provides an artifact with all the logs at the end

## How to use it

!!! info
    Your need to link your remote database in the environment variables file, so make sure that you are using the correct database credentials.

1. Ensure that your project has a premade environment file such as `.env.testing` in example, which contains the variables that will be used by the project.
2. Add this job URL inside the `include` list of your `.gitlab-ci.yml` file (see the [quick setup](/use-the-hub/#quick-setup)). You can specify [a fixed version](#changelog) instead of `latest`.
    ```yaml
      - remote: 'https://jobs.r2devops.io/latest/artisan_migrate.yml'
    ```
3. If you need to customize the job (stage, variables, ...) 👉 check the [jobs
   customization](/use-the-hub/#jobs-customization)
4. Well done, your job is ready to work ! 😀


## Job details

* Job name: `artisan_migrate`
* Default stage: `build`
* Docker image: [`edbizarro/gitlab-ci-pipeline-php:7.3`](https://hub.docker.com/r/edbizarro/gitlab-ci-pipeline-php){:target="_blank"}
* When: `always`


### Variables

| Name | Default | Description |
| ---- | ------- | --------------- |
| `PROJECT_ROOT` | `.` | Path to the directory containing environment variables |
| `ENV_NAME` | `.env.testing` | Name of the environment variables file to use | 
| `ARTISAN_MIGRATE_OPTIONS` | ` ` | Options for command `php artisan migrate` |
| `ARTISAN_OUTPUT` | `artisan_migration.log` | Name for logs file |


### Artifact

When the job is done, the command output will be available under the file name `ARTISAN_OUTPUT` as an artifact.
 No newline at end of file
+26 −0
Original line number Diff line number Diff line
# Job from R2Devops hub --> r2devops.io

stages:
  - build

artisan_migrate:
  stage: build
  image:
    name: edbizarro/gitlab-ci-pipeline-php:7.3
    entrypoint: [""]
  variables:
    PROJECT_ROOT: "."
    ENV_NAME: ".env.testing"
    ARTISAN_MIGRATE_OPTIONS: ""
    ARTISAN_OUTPUT: "artisan_migration.log"
  script:
    # Working directory
    - cd $PROJECT_ROOT
    # Setup .env
    - cp -f ${ENV_NAME} .env
    # Run the migration
    - php artisan migrate ${ARTISAN_MIGRATE_OPTIONS} >&1 | tee ${ARTISAN_OUTPUT}
  artifacts:
    expose_as: "artisan migration"
    paths:
      - "${ARTISAN_OUTPUT}"
+13 −0
Original line number Diff line number Diff line
name: artisan_migrate
description: A ready-to-use job for migrating your database
default_stage: build
icon: 🗃️
maintainer: moha-s
license: MIT
images:
    "edbizarro/gitlab-ci-pipeline-php": "7.3"
tools:
labels:
    - GitLab
    - Artisan
    - Database
+0 −0

Empty file added.

+1 −0
Original line number Diff line number Diff line
* Initial version