Files
kulakpos_web/walkthroughs/2026-04-13_00dedd09_Walkthrough__Initial_Database_Data_Seeding.md
eko54r 05fd3230b8
All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 5m14s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 17s
Build, Push and Deploy / deploy-staging (push) Successful in 41s
Build, Push and Deploy / deploy-production (push) Has been skipped
update marketing
2026-05-14 11:55:22 +07:00

1.4 KiB

Walkthrough - Initial Database Data Seeding

I have implemented a database-agnostic Laravel Seeder to handle the initial database population from the db/kulakposmysql.sql file. This approach is compatible with both MySQL and PostgreSQL.

Changes Made

Database Seeders

  • Created InitialDataSeeder.php:
    • This seeder dynamically reads the db/kulakposmysql.sql file.
    • It parses INSERT INTO statements and uses Laravel's DB::table()->insert() to populate the tables.
    • It automatically detects the database driver (MySQL or PostgreSQL) and applies the correct commands to temporarily disable foreign key constraints during the import.
    • It uses Laravel's Schema Builder to map data values to the correct table columns.

How to Verify

  1. Run standard migrations first (if not already done):
    php artisan migrate
    
  2. Run the Initial Data Seeder:
    php artisan db:seed --class=InitialDataSeeder
    
  3. Verify Data: Check your database (e.g., users, businesses) to confirm that the data from the SQL file has been correctly imported.

Tip

This seeder is designed to be safe for PostgreSQL, which was the cause of the previous failure. It uses the session_replication_role setting to handle foreign keys on PostgreSQL.