Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove separate vector database #720

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ DB_DATABASE="biigle"
DB_USERNAME="biigle"
DB_PASSWORD="secret"

VECTOR_DB_HOST="vector_database"
VECTOR_DB_PORT=5432
VECTOR_DB_DATABASE="biigle"
VECTOR_DB_USERNAME="biigle"
VECTOR_DB_PASSWORD="secret"

VOLUME_ADMIN_STORAGE_DISKS=local

BROADCAST_DRIVER=pusher
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ jobs:
- name: Start test database
run: |
docker-compose up -d --no-build database_testing
docker-compose up -d --no-build vector_database_testing
sleep 5

- name: Run tests
Expand Down Expand Up @@ -80,7 +79,6 @@ jobs:
- name: Start test database
run: |
docker-compose up -d --no-build database_testing
docker-compose up -d --no-build vector_database_testing
sleep 5

- name: Run tests
Expand Down
15 changes: 0 additions & 15 deletions config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,6 @@
'sslmode' => 'prefer',
],

'pgvector' => [
'driver' => 'pgsql',
'url' => env('VECTOR_DATABASE_URL'),
'host' => env('VECTOR_DB_HOST', 'localhost'),
'port' => env('VECTOR_DB_PORT', '5432'),
'database' => env('VECTOR_DB_DATABASE', 'forge'),
'username' => env('VECTOR_DB_USERNAME', 'forge'),
'password' => env('VECTOR_DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'search_path' => 'public',
'sslmode' => 'prefer',
],

'sqlsrv' => [
'driver' => 'sqlsrv',
'url' => env('DATABASE_URL'),
Expand Down
15 changes: 13 additions & 2 deletions database/migrations/2022_08_03_000000_create_vector_extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
*/
public function up()
{
DB::connection('pgvector')->statement('CREATE EXTENSION IF NOT EXISTS vector');
// The pgvector connection was removed later so it may not always be present.
// There is a second migration that enables pgvector for the default connection.
// See: https://github.com/biigle/maia/pull/150
if (!is_null(config('database.connections-pgvector'))) {
DB::connection('pgvector')
->statement('CREATE EXTENSION IF NOT EXISTS vector');

}
}

/**
Expand All @@ -21,6 +28,10 @@ public function up()
*/
public function down()
{
DB::connection('pgvector')->statement('DROP EXTENSION IF EXISTS vector');
if (!is_null(config('database.connections-pgvector'))) {
DB::connection('pgvector')
->statement('DROP EXTENSION IF NOT EXISTS vector');

}
}
};
26 changes: 26 additions & 0 deletions database/migrations/2023_12_12_150300_create_vector_extension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::statement('CREATE EXTENSION IF NOT EXISTS vector');
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
DB::statement('DROP EXTENSION IF NOT EXISTS vector');
}
};
26 changes: 1 addition & 25 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ services:
depends_on:
- app
- database_testing
- vector_database_testing
build:
context: ./
dockerfile: .docker/worker.dockerfile
Expand Down Expand Up @@ -66,7 +65,7 @@ services:

# The database
database:
image: postgres:14-alpine
image: ghcr.io/biigle/pgvector
volumes:
- dbdata:/var/lib/postgresql/data
- ./:/data
Expand All @@ -77,28 +76,7 @@ services:
ports:
- "54320:5432"

vector_database:
image: ghcr.io/biigle/pgvector
volumes:
- vecdbdata:/var/lib/postgresql/data
- ./:/data
environment:
- "POSTGRES_DB=biigle"
- "POSTGRES_USER=biigle"
- "POSTGRES_PASSWORD=secret"
ports:
- "54321:5432"

database_testing:
image: postgres:14-alpine
tmpfs:
- /var/lib/postgresql/data
environment:
- "POSTGRES_DB=biigle"
- "POSTGRES_USER=biigle"
- "POSTGRES_PASSWORD=secret"

vector_database_testing:
image: ghcr.io/biigle/pgvector
tmpfs:
- /var/lib/postgresql/data
Expand All @@ -109,5 +87,3 @@ services:

volumes:
dbdata:
vecdbdata:

4 changes: 0 additions & 4 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,5 @@
<env name="DB_DATABASE" value="biigle"/>
<env name="DB_USERNAME" value="biigle"/>
<env name="DB_PASSWORD" value="secret"/>
<env name="VECTOR_DB_HOST" value="vector_database_testing"/>
<env name="VECTOR_DB_DATABASE" value="biigle"/>
<env name="VECTOR_DB_USERNAME" value="biigle"/>
<env name="VECTOR_DB_PASSWORD" value="secret"/>
</php>
</phpunit>
27 changes: 0 additions & 27 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,17 @@

use Biigle\Tests\CreatesApplication;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\RefreshDatabaseState;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Support\Facades\Queue;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;

class TestCase extends BaseTestCase
{
use CreatesApplication, MockeryPHPUnitIntegration, RefreshDatabase;
use RefreshDatabase {
refreshTestDatabase as protected originalRefreshTestDatabase;
}

public static $cachedPdo;
public static $cachedVectorPdo;

protected $baseUrl = 'http://localhost';

protected $connectionsToTransact = [
'pgsql',
'pgvector',
];

/**
* Default preparation for each test.
*/
Expand Down Expand Up @@ -54,21 +43,5 @@ protected function beforeRefreshingDatabase()
} else {
static::$cachedPdo = DB::getPdo();
}

if (static::$cachedVectorPdo) {
DB::connection('pgvector')->setPdo(static::$cachedVectorPdo);
} else {
static::$cachedVectorPdo = DB::connection('pgvector')->getPdo();
}
}

// Custom implementation to wipe the vector database, too.
protected function refreshTestDatabase()
{
if (!RefreshDatabaseState::$migrated) {
$this->artisan('db:wipe', ['--database' => 'pgvector']);
}

$this->originalRefreshTestDatabase();
}
}
Loading