PHPackages                             bowlofsoup/couchbase-migrations-bundle - 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. bowlofsoup/couchbase-migrations-bundle

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

bowlofsoup/couchbase-migrations-bundle
======================================

Migrations for Couchbase in a Symfony bundle.

2.1.1(2y ago)493MITPHPPHP &gt;=8.3

Since Aug 30Pushed 2y ago2 watchersCompare

[ Source](https://github.com/BowlOfSoup/CouchbaseMigrationsBundle)[ Packagist](https://packagist.org/packages/bowlofsoup/couchbase-migrations-bundle)[ RSS](/packages/bowlofsoup-couchbase-migrations-bundle/feed)WikiDiscussions master Synced today

READMEChangelog (8)Dependencies (10)Versions (11)Used By (0)

Couchbase Migrations Bundle
===========================

[](#couchbase-migrations-bundle)

With this Symfony bundle you can generate and execute migrations on a Couchbase database. It works kind of like [Doctrine Migrations](https://github.com/doctrine/migrations).

- Generate blank migrations and fill them to e.g. make new indexes on buckets or upsert/remove documents.
- It keeps in check which migrations that have already been executed and which still need to be done.
- Usable via Symfony commands.

Prerequisites
-------------

[](#prerequisites)

- PHP 8.3 or higher with Couchbase extension

Installation and setup
----------------------

[](#installation-and-setup)

Install the bundle via composer.

```
composer require bowlofsoup/couchbase-migrations-bundle

```

Add the bundle to your `AppKernel.php`.

```
$bundles = [
    ...
    new \BowlOfSoup\CouchbaseMigrationsBundle\CouchbaseMigrationsBundle()
    ...
];

```

Create a `CouchbaseMigrations` directory in your `app` directory. This will contain all the generated blank migrations.

```
$ mkdir CouchbaseMigrations

```

Add the `config/packages/couchbase_migrations_bundle.yaml`.

```
couchbase_migrations:
    host: '%env(COUCHBASE_MIGRATIONS_HOST)%'
    user: '%env(COUCHBASE_MIGRATIONS_USER)%'
    password: '%env(COUCHBASE_MIGRATIONS_PASSWORD)%'
    bucket_migrations: '%env(COUCHBASE_MIGRATIONS_BUCKET_MIGRATIONS)%'
    bucket_default: '%env(COUCHBASE_MIGRATIONS_DEFAULT_BUCKET)%'

```

Optional you can also configure the port if it is not standard.

```
couchbase_migrations:
    port: '%env(COUCHBASE_MIGRATIONS_PORT)%'

```

In your .env file, define the above values:

```
COUCHBASE_MIGRATIONS_HOST="127.0.0.1"
COUCHBASE_MIGRATIONS_USER="couchbase_user"
COUCHBASE_MIGRATIONS_PASSWORD="couchbase_password"
COUCHBASE_MIGRATIONS_BUCKET_MIGRATIONS="default"
COUCHBASE_MIGRATIONS_DEFAULT_BUCKET="default"

```

- **`bucket_migrations`** must hold the bucket in which you want to store which migration has already been done. Not mandatory, but then a bucket named `migrations` must be accessible.
- **`bucket_default`** must hold your default bucket. If you do not have a default bucket, use `%couchbase_migrations.bucket_migrations%` as option.

Usage
-----

[](#usage)

#### Generate migration

[](#generate-migration)

```
bin/console couchbase:migrations:generate

```

This will generate a blank migration file in `CouchbaseMigrations/` for you to fill.

#### Migrate all

[](#migrate-all)

```
bin/console couchbase:migrations:migrate

```

This will execute all migrations that still need to be done.

The configured bucket (`bucket_migrations` in the config file) will contain a document (`migrations::versions`) which contains the already migrated.

#### Execute a single migration

[](#execute-a-single-migration)

```
bin/console couchbase:migrations:execute VERSION_NUMBER [--no-verbose] [--down]

```

This will execute the given version (file in `CouchbaseMigrations/`). Replace `VERSION_NUMBER` with the version (**date-time part** of the file) you want to execute. You can execute a version indefinitely: will not be kept track of.

#### Flush all data in a bucket, except the migrations

[](#flush-all-data-in-a-bucket-except-the-migrations)

```
bin/console couchbase:migrations:flush-data BUCKET_NAME

```

Flushes all the data in a bucket, if flushing is enabled for that bucket, except the migrations version document. Replace `BUCKET_NAME` with the name of the bucket for which you want the data to be flushed. Defaults to the configured bucket.

Can be handy if you want to reset all data in a bucket, but do not want to lose your migrations.

#### Create a bucket

[](#create-a-bucket)

```
bin/console couchbase:migrations:create-bucket [BUCKET_NAME] [--index]

```

Creates a bucket, optional name (takes default configured) and optionally creating a primary index.

#### Remove a bucket

[](#remove-a-bucket)

```
bin/console couchbase:migrations:remove-bucket [BUCKET_NAME]

```

Creates a bucket, optional name (takes default configured).

How to write a migration
------------------------

[](#how-to-write-a-migration)

When you have generated a migration, open the file and use the `up` function. Example:

```
public function up()
{
    // Use only if you want to select a different bucket than the one configured.
    $this->selectBucket('some-other-bucket-name');

    $this->bucketRepository->query(
        'CREATE INDEX `i_someindexname` ON `bucketname`(`propertyname`) WHERE (`someotherpropertyname` = "propertycontent")'
    );
}

```

or

```
public function up()
{
    // Use only if you want to select a different bucket than the one configured.
    $bucket = $this->selectBucket('some-other-bucket-name');

    $result = $bucket->get('some-document-key');
    $documentContent = $result->value;

    $bucket->insert('some-other-document-key', $documentContent);
}

```

Downgrading is also supported for the **execute** command, just add a method `down()` to the migration.

```
public function down()
{
    $this->bucketRepository->query(
        'the opposite of the up() query'
    );
}

```

So:

- The `$this->bucketRepository` can be used to make it easier to do queries on a bucket (like named parameters).
- You can also directly do actions on the bucket by using the return value of `$this->selectBucket()`.

Note: The Bucket returned by `selectBucket()` and the result returned by `$bucket->get()` are both small backwards- compatible classes to not break old migrations defined with the previous version of this bundle. If you need the actual Couchbase Bucket, you can use `$bucket->getBucket()`, if you need the actual Couchbase result you can get that by calling `$result->getResult()`.

How to use as standalone application
------------------------------------

[](#how-to-use-as-standalone-application)

You can use this bundle as standalone application, so, not use it within a Symfony installation. This is also perfect for development.

- Checkout this repository and create an `app` directory within the `src` directory.
- Create a `src/CouchbaseMigrations` directory.
- Create a `src/app/parameters.yml` which holds the config parameters.

Fill the `src/app/parameters.yml` file with:

```
parameters:
  kernel.project_dir:

  couchbase_bucket:

  couchbase_migrations.bucket_migrations:
  couchbase_migrations.host:
  couchbase_migrations.user:
  couchbase_migrations.password:

```

- The `kernel.project_dir` option must hold the full path the the `src` directory.
- See 'Installation and setup' for more info on the options.

Contributing
------------

[](#contributing)

You are more then welcome to fork this repository, make changes and create a pull request back.

- Create an issue and state the changes you want to make.
- In your commit messages, refer to this issue.
- Be sure to run `vendor/bin/php-cs-fixer fix` before you commit code changes. This will make the changed code adhere to the coding standards.

Upgrading to 2.x
----------------

[](#upgrading-to-2x)

When you're upgrading from version 1.0, you need to do two things:

- Update the configuration according to the above information
- Move the path of the migrations. The `app/` directory is gone in new Symfony versions, the `CouchbaseMigrations` folder should now be in the root of your project

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity84

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 88.6% 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 ~303 days

Recently: every ~513 days

Total

8

Last Release

734d ago

Major Versions

v0.1.0 → 1.0.02018-11-12

1.0.3 → 2.02024-05-29

PHP version history (2 changes)v0.1.0PHP &gt;=7.0

2.0PHP &gt;=8.3

### Community

Maintainers

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

---

Top Contributors

[![BowlOfSoup](https://avatars.githubusercontent.com/u/19224810?v=4)](https://github.com/BowlOfSoup "BowlOfSoup (31 commits)")[![rachelle-scheijen](https://avatars.githubusercontent.com/u/5584054?v=4)](https://github.com/rachelle-scheijen "rachelle-scheijen (2 commits)")[![dmytroliashko](https://avatars.githubusercontent.com/u/49982523?v=4)](https://github.com/dmytroliashko "dmytroliashko (1 commits)")[![skoop](https://avatars.githubusercontent.com/u/90003?v=4)](https://github.com/skoop "skoop (1 commits)")

---

Tags

couchbasedatabase-managementdatabase-migrationssymfonysymfony-bundlesymfony3

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/bowlofsoup-couchbase-migrations-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/bowlofsoup-couchbase-migrations-bundle/health.svg)](https://phpackages.com/packages/bowlofsoup-couchbase-migrations-bundle)
```

PHPackages © 2026

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