PHPackages                             loadinglucian/laravel-optimal-sqlite - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. loadinglucian/laravel-optimal-sqlite

ActiveLibrary[Database &amp; ORM](/categories/database)

loadinglucian/laravel-optimal-sqlite
====================================

Production-oriented SQLite defaults for Laravel migrations and runtime connections.

v0.0.2(1mo ago)026↓100%MITPHPPHP ^8.3

Since Apr 28Pushed 1mo agoCompare

[ Source](https://github.com/loadinglucian/laravel-optimal-sqlite)[ Packagist](https://packagist.org/packages/loadinglucian/laravel-optimal-sqlite)[ RSS](/packages/loadinglucian-laravel-optimal-sqlite/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (9)Versions (3)Used By (0)

Laravel Optimal SQLite
======================

[](#laravel-optimal-sqlite)

- [Introduction](#introduction)
- [Requirements](#requirements)
- [Installation](#installation)
- [What It Does](#what-it-does)
- [How This Differs From Nuno's Package](#how-this-differs-from-nunos-package)
- [Configuration](#configuration)
- [Existing Databases](#existing-databases)
- [Testing](#testing)
- [License](#license)

Introduction
------------

[](#introduction)

SQLite is a great fit for many Laravel applications, but its best production settings need to be applied at the right time. Some settings belong to each connection, while others affect the database file itself and must be applied before Laravel creates schema tables.

Laravel Optimal SQLite gives your Laravel application production-oriented SQLite defaults without adding a custom command to remember. When you run Laravel's normal migration commands, the package prepares empty SQLite database files before the migrations table is created. At runtime, it applies sensible SQLite connection defaults to every configured SQLite connection.

This package was inspired by Nuno Maduro's [`nunomaduro/laravel-optimize-database`](https://github.com/nunomaduro/laravel-optimize-database). That package showed how useful a small SQLite optimization layer can be for Laravel. Laravel Optimal SQLite takes the idea further by handling the lifecycle issues around `page_size`, WAL mode, `VACUUM`, and `migrate:fresh`.

Requirements
------------

[](#requirements)

Laravel Optimal SQLite requires a Laravel application using a file-backed SQLite connection. Runtime connection defaults may be applied to any SQLite connection, but file-level settings such as `page_size` and `auto_vacuum` cannot be applied to `:memory:` databases.

Laravel package discovery should be enabled so the service provider can register automatically. If your application disables package discovery, manually register the provider:

```
Loadinglucian\LaravelOptimalSqlite\OptimalSqliteServiceProvider::class,
```

After installing the package, run your normal Laravel migrations. The package optimizes empty SQLite database files during `php artisan migrate` and preserves those file settings during `php artisan migrate:fresh`.

Installation
------------

[](#installation)

You may install the package with Composer:

```
composer require loadinglucian/laravel-optimal-sqlite
```

Laravel will discover the service provider automatically.

After installation, continue using Laravel's standard migration commands:

```
php artisan migrate
php artisan migrate:fresh
```

You do not need to run a package-specific optimization command.

What It Does
------------

[](#what-it-does)

The package applies two kinds of SQLite settings.

Runtime connection settings are applied to every configured SQLite connection before Laravel opens it:

```
PRAGMA busy_timeout = 5000
PRAGMA cache_size = -20000
PRAGMA foreign_keys = ON
PRAGMA mmap_size = 2147483648
PRAGMA temp_store = MEMORY
PRAGMA synchronous = NORMAL
PRAGMA journal_mode = WAL

```

File-level settings are applied automatically before migrations create tables:

```
PRAGMA journal_mode = DELETE
PRAGMA auto_vacuum = INCREMENTAL
PRAGMA page_size = 32768
VACUUM
PRAGMA journal_mode = WAL

```

This sequence matters. SQLite can only apply `page_size` at database creation or during `VACUUM` while the database is not in WAL mode. The package temporarily leaves WAL mode, applies the file settings, vacuums the empty database file, and then restores WAL mode.

The package also replaces Laravel's SQLite `db:wipe` behavior for file-backed SQLite databases. Laravel normally empties the SQLite file during `db:wipe`, which resets file-level settings such as `page_size`. Laravel Optimal SQLite drops schema objects instead, so repeated `migrate:fresh` runs keep the optimized file format intact.

How This Differs From Nuno's Package
------------------------------------

[](#how-this-differs-from-nunos-package)

Nuno's package provided the useful starting point: codify a production-ready SQLite profile for Laravel. Laravel Optimal SQLite keeps that spirit, but it changes the delivery mechanism.

This package does not publish a migration stub. Laravel creates the `migrations`table before running the first migration, so a "first" migration is still too late for some SQLite file settings unless it performs a careful `VACUUM` flow. Instead, this package hooks into Laravel's normal `migrate` command and applies file-level settings before the migrations table exists.

This package also avoids an extra Artisan command in your day-to-day workflow. You continue running `php artisan migrate` and `php artisan migrate:fresh`.

Finally, this package tests the observed SQLite values after tuning. The test suite verifies the real `PRAGMA` values, including `page_size`, `auto_vacuum`, WAL mode, runtime connection settings, and repeated `migrate:fresh` behavior.

Configuration
-------------

[](#configuration)

By default, every configured SQLite connection receives the package defaults. You may override runtime settings directly in your `config/database.php`connection array:

```
'sqlite' => [
    'driver' => 'sqlite',
    'database' => database_path('database.sqlite'),
    'busy_timeout' => 10000,
    'journal_mode' => 'WAL',
    'synchronous' => 'NORMAL',
    'pragmas' => [
        'cache_size' => -40000,
        'mmap_size' => 2147483648,
        'temp_store' => 'MEMORY',
    ],
],
```

The file-level defaults are intentionally not exposed through environment variables. They affect the database file format and should remain stable across environments.

Existing Databases
------------------

[](#existing-databases)

The automatic migration flow only optimizes SQLite files that do not yet have user-created tables. Existing populated databases are skipped so the package does not unexpectedly rewrite a production database file.

Before applying file-level changes to an existing SQLite database, take a backup. Then perform the maintenance explicitly in your own deployment process or call the `SQLiteDatabaseOptimizer` service from a controlled script.

Testing
-------

[](#testing)

You may run the package test suite with Composer:

```
composer test
```

The tests use real temporary SQLite files and assert the actual post-tuning `PRAGMA` values.

License
-------

[](#license)

Laravel Optimal SQLite is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance91

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

42d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a8a480ff5decb958b99aa7e82d8a7a41310ef829b21a8616ac81a5f6f2e4bba1?d=identicon)[loadinglucian](/maintainers/loadinglucian)

---

Top Contributors

[![loadinglucian](https://avatars.githubusercontent.com/u/235876?v=4)](https://github.com/loadinglucian "loadinglucian (4 commits)")

---

Tags

laraveldatabasesqliteoptimizationwal

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/loadinglucian-laravel-optimal-sqlite/health.svg)

```
[![Health](https://phpackages.com/badges/loadinglucian-laravel-optimal-sqlite/health.svg)](https://phpackages.com/packages/loadinglucian-laravel-optimal-sqlite)
```

###  Alternatives

[laravel/ai

The official AI SDK for Laravel.

9782.1M153](/packages/laravel-ai)[illuminate/queue

The Illuminate Queue package.

20432.2M1.5k](/packages/illuminate-queue)[itpathsolutions/dbstan

Database Standardization and Analysis Tool for Laravel

442.1k](/packages/itpathsolutions-dbstan)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3359.7k2](/packages/toponepercent-baum)[orptech/laravel-migration-partition

Laravel extensions that extends Illuminate to enable partitioned table creation within Laravel migrations.

3628.3k](/packages/orptech-laravel-migration-partition)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
