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

Fix couchdb setup and add a note on how to remove the container #6915

Merged
merged 5 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions src/plugins/persistence/couch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ sh ./src/plugins/persistence/couch/replace-localstorage-with-couchdb-indexhtml.s

Open MCT will now use your local CouchDB container as its persistence store. Access the CouchDB instance manager by visiting <http://localhost:5984/_utils>.

### Removing CouchDB Container completely

To completely remove the CouchDB container and volumes:

```sh
docker stop couch-couchdb-1;docker rm couch-couchdb-1;docker volume rm couch_couchdb
```

## macOS

While we highly recommend using the CouchDB docker-compose installation, it is still possible to install CouchDB through other means.
Expand Down
51 changes: 33 additions & 18 deletions src/plugins/persistence/couch/setup-couchdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ if [ "${COUCH_ADMIN_PASSWORD}" ]; then
CURL_USERPASS_ARG+=":${COUCH_ADMIN_PASSWORD}"
fi

# Functions
resource_exists() {
response=$(curl -u "${CURL_USERPASS_ARG}" -s -o /dev/null -I -w "%{http_code}" $1);
if [ "200" == "${response}" ]; then
Expand Down Expand Up @@ -77,17 +76,24 @@ update_db_permissions() {
fi
}

create_system_tables() {
local system_tables=("_users" "_replicator")
for table in "${system_tables[@]}"; do
echo "Creating $table database"
response=$(curl -su "${CURL_USERPASS_ARG}" -X PUT $COUCH_BASE_LOCAL/$table)
if [ "{\"ok\":true}" == "${response}" ]; then
echo "Successfully created $table database"
else
echo "Unable to create $table database"
fi
done
create_users_table() {
echo "Creating _users database"
response=$(curl -su "${CURL_USERPASS_ARG}" -XPUT $COUCH_BASE_LOCAL/_users)
if [ "{\"ok\":true}" == "${response}" ]; then
echo "Successfully created _users database"
else
echo "Unable to create _users database"
fi
}

create_replicator_table() {
echo "Creating _replicator database"
response=$(curl -su "${CURL_USERPASS_ARG}" -XPUT $COUCH_BASE_LOCAL/_replicator)
if [ "{\"ok\":true}" == "${response}" ]; then
echo "Successfully created _replicator database"
else
echo "Unable to create _replicator database"
fi
}

# Main script execution
Expand All @@ -100,13 +106,22 @@ else
echo "Admin user exists"
fi

# Check if system tables exist; if not, create them.
system_tables_exist=$(resource_exists $COUCH_BASE_LOCAL/_users)
if [ "TRUE" == "${system_tables_exist}" ]; then
echo "System tables exist, skipping creation"
# Check if the _users table exists; if not, create it.
users_table_exists=$(resource_exists $COUCH_BASE_LOCAL/_users)
if [ "FALSE" == "${users_table_exists}" ]; then
echo "Creating _users table"
create_users_table
else
echo "_users table already exists, skipping creation"
fi

# Check if the _replicator table exists; if not, create it.
replicator_table_exists=$(resource_exists $COUCH_BASE_LOCAL/_replicator)
if [ "FALSE" == "${replicator_table_exists}" ]; then
echo "Creating _replicator table"
create_replicator_table
else
echo "Fresh install, creating system tables"
create_system_tables
echo "_replicator table already exists, skipping creation"
fi

# Check if the database exists; if not, create it.
Expand Down