Skip to content

[Migration] Artisan Commands and Use Cases

Nikita Voronov edited this page Dec 15, 2024 · 1 revision

This document outlines the Artisan commands available in the HIKO project and provides use-cases for each command.


Artisan Commands Overview

Artisan is Laravel's powerful command-line interface, enhanced by HIKO with custom commands to manage multi-tenancy and data import operations efficiently.

Import Commands

HIKO provides several Artisan commands to import various data types into tenant-specific tables. Each command targets a specific data category, ensuring organized and efficient data migration.

hiko:import-keyword

Description: Imports keywords from a previous version into the tenant's keywords table.

Usage: php artisan hiko:import-keyword

Use Case: Use this command to import a list of predefined keywords when setting up or updating a tenant's database.

hiko:import-users

Description: Imports users from a previous version into the tenant's users table.

Usage: php artisan hiko:import-users

Use Case: Import user accounts for a specific tenant, migrating them from a previous system or data source.

hiko:import-professions

Description: Imports professions from a previous version into the tenant's professions table.

Usage: php artisan hiko:import-professions

Use Case: Import a list of professions when setting up a tenant, which can be used later for categorizing or searching in the application.

hiko:import-places

Description: Imports places from a previous version into the tenant's places table.

Usage: php artisan hiko:import-places

Use Case: Load geographic locations to be used as reference when importing data.

hiko:import-identities

Description: Imports identities from a previous version into the tenant's identities table.

Usage: php artisan hiko:import-identities

Use Case: Import information about individuals or organizations related to the content within a specific tenant.

hiko:import-letters

Description: Imports letters from a previous version into the tenant's letters table with a specified prefix.

Usage: php artisan hiko:import-letters {prefix}

Parameters:

  • {prefix}: The table prefix for the tenant (e.g., blekastad__).

Example:

php artisan hiko:import-letters blekastad__

Use Case: Used to bulk import letters for a specific tenant.

hiko:import-media

Description: Imports media (images) from a previous version into the tenant's media table.

Usage: php artisan hiko:import-media

Use Case: Import image files or other media assets associated with letters or other content of a specific tenant.

Tenant Management Commands

tenant:add

Description: Adds a new tenant and creates its associated database tables with the appropriate prefix.

Usage: php artisan tenant:add

Process:

  • Prompts the user to enter a new tenant name.
  • Generates a unique table prefix.
  • Adds the new tenant to the tenants table.
  • Creates tables with the generated prefix.

Use Case: Create new data containers for each client to provide them with separate environments.

Migration Handling

php artisan migrate --path="database/migrations/create_migration.php"

Description: Runs a custom migration that allows you to perform all actions.

Usage: php artisan migrate --path="database/migrations/create_migration.php

The migration will ask you to choose one of these options:

  • (1) Add New Tenant: For adding a new tenant to an existing multi-tenant application.
  • (2) Run Migrations: For creating or updating all migrations (core, tenants, global). If this is the first migration, it will create the first admin user and demo tenant if the database is empty.
  • (3) Exit: To exit without any actions.

Use Cases:

  • New Application Setup: To start from scratch and set up all tables, an admin user, and a demo tenant with one command.
  • Adding a New Tenant: If you select Add New Tenant, it will prompt for a new tenant name and create the tables with the generated prefix.
  • Extending Existing Project: If you select Extend Existing App, it will allow you to update global tables and add a tenant_id column to the users table if it doesn't exist.

php artisan migrate:rollback

Description: Roll back the latest migration.

Usage:

php artisan migrate:rollback

Will roll back the last migration that was applied.

Usage:

php artisan migrate:rollback --step=n

Will rollback the last n batches of migrations.

Use Case: Used to revert migrations if you need to make changes to the code and start again.

php artisan migrate:status

Description: View the status of migrations, including migrations that have been run and migrations pending to run.

Usage: php artisan migrate:status

Use Case: Check if all migrations have been run correctly.