OCI Database Migration Service Client for Node.js

2.130.0 · active · verified Wed Apr 22

The `oci-databasemigration` package provides a Node.js client for interacting with the Oracle Cloud Infrastructure (OCI) Database Migration Service. It allows developers to programmatically manage resources related to database migrations within the OCI ecosystem, such as creating, managing, and monitoring migration jobs. This module is an integral part of the broader OCI TypeScript SDK and ships with comprehensive TypeScript type definitions, enabling robust development with full type safety. As of version 2.130.0, the SDK is actively maintained, with a rapid release cadence (typically multiple minor versions per month, as evidenced by recent release logs) that consistently introduces support for new OCI services, features, and API endpoints across various OCI components, not solely Database Migration. Its key differentiator is being the official, idiomatic client for OCI services, ensuring seamless compatibility and strict alignment with OCI's continuously evolving API landscape. Successful usage requires an existing OCI account, a configured user with appropriate IAM policies, and an API signing key pair for authentication.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the OCI Database Migration client and list existing migrations within a specified OCI compartment, using credentials from the default OCI config file.

import * as databasemigration from 'oci-databasemigration';
import * as common from 'oci-common';

// IMPORTANT: Ensure your OCI configuration file (typically ~/.oci/config) is set up
// and the profile is configured for API signing keys.
// You can also pass authentication details directly, but a config file is common.
// For sensitive keys, use environment variables or OCI Vault.
// Example environment variables for authentication (not recommended for production keys):
// process.env.OCI_COMPARTMENT_ID
// process.env.OCI_USER_OCID
// process.env.OCI_TENANCY_OCID
// process.env.OCI_FINGERPRINT
// process.env.OCI_PRIVATE_KEY_PATH
// process.env.OCI_REGION

async function listOciDatabaseMigrations() {
  try {
    // Initialize the authentication provider using the default OCI config file and profile
    const authProvider = new common.ConfigFileAuthenticationDetailsProvider();

    // Create a client for the Database Migration Service
    const client = new databasemigration.DatabaseMigrationClient({
      authenticationDetailsProvider: authProvider,
      region: authProvider.getRegion() // Use region from config or explicitly set
    });

    // Define the compartment ID where your migrations are located
    const compartmentId = process.env.OCI_COMPARTMENT_ID || 'ocid1.compartment.oc1..examplecompartmentid'; 
    if (compartmentId === 'ocid1.compartment.oc1..examplecompartmentid') {
      console.warn('Using a placeholder compartment ID. Please set OCI_COMPARTMENT_ID environment variable or replace it directly.');
    }

    // Create a request object to list migrations in the specified compartment
    const listMigrationsRequest: databasemigration.requests.ListMigrationsRequest = {
      compartmentId: compartmentId,
      lifecycleState: databasemigration.models.Migration.LifecycleState.Active // Optional: Filter by active migrations
    };

    console.log(`Listing OCI Database Migrations in compartment: ${compartmentId}...`);

    // Call the API to list migrations
    const response = await client.listMigrations(listMigrationsRequest);

    if (response.items && response.items.length > 0) {
      console.log(`Found ${response.items.length} migrations:`)
      response.items.forEach(migration => {
        console.log(`- ${migration.displayName} (OCID: ${migration.id}, State: ${migration.lifecycleState})`);
      });
    } else {
      console.log('No database migrations found in the specified compartment.');
    }
  } catch (error) {
    console.error('Error listing OCI Database Migrations:', error);
    if (error instanceof Error && error.message.includes('AuthNFailed')) {
        console.error('Authentication failed. Please check your OCI config file and API key setup.');
    } else if (error instanceof Error && error.message.includes('NotFound')) {
        console.error('Resource not found. Check compartment ID and permissions.');
    }
  }
}

listOciDatabaseMigrations();

view raw JSON →