Skip to content
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
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ services:
- ./docker/00-init-roles.sql:/docker-entrypoint-initdb.d/00-init-roles.sql
- ./treebase-core/src/main/resources/TBASE2_POSTGRES_CREATION.sql:/docker-entrypoint-initdb.d/01-schema.sql
- ./treebase-core/src/main/resources/initTreebase.sql:/docker-entrypoint-initdb.d/02-init.sql
- ./docker/03-migration-hibernate-sequence.sql:/docker-entrypoint-initdb.d/03-migration-hibernate-sequence.sql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U treebase"]
interval: 10s
Expand Down
14 changes: 14 additions & 0 deletions docker/03-migration-hibernate-sequence.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- Migration script to add hibernate_sequence if it doesn't exist
-- This sequence is required by Hibernate's @CollectionId annotation
-- for generating collection_id values in sub_matrix and sub_treeblock tables

DO $$
BEGIN
IF NOT EXISTS (SELECT FROM pg_catalog.pg_sequences WHERE sequencename = 'hibernate_sequence') THEN
CREATE SEQUENCE hibernate_sequence;
RAISE NOTICE 'Created hibernate_sequence';
ELSE
RAISE NOTICE 'hibernate_sequence already exists';
END IF;
END
$$;
9 changes: 9 additions & 0 deletions docker/entrypoint-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ until pg_isready -h postgres -U treebase; do
done
echo "PostgreSQL is ready!"

# Run database migrations
echo "Running database migrations..."
if [ -f "/app/docker/03-migration-hibernate-sequence.sql" ]; then
PGPASSWORD=treebase psql -h postgres -U treebase -d treebase -f /app/docker/03-migration-hibernate-sequence.sql || echo "Warning: Migration may have failed"
else
echo "Migration script not found at /app/docker/03-migration-hibernate-sequence.sql"
fi
echo "Database migrations complete!"

# Check if we need to build the project
if [ ! -f "/app/treebase-web/target/treebase-web.war" ]; then
echo "Building TreeBASE web application..."
Expand Down
4 changes: 4 additions & 0 deletions treebase-core/src/main/resources/TBASE2_POSTGRES_CREATION.sql
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ CREATE SEQUENCE help_id_sequence;
ALTER TABLE help ALTER COLUMN help_id SET DEFAULT nextval('help_id_sequence');
-- alter sequence help_id_sequence restart with 183;

-- hibernate_sequence is used by Hibernate's @CollectionId annotation
-- for generating collection_id values in sub_matrix and sub_treeblock tables
CREATE SEQUENCE hibernate_sequence;

CREATE TABLE itemdefinition
(
itemdefinition_id bigint NOT NULL,
Expand Down