OCI Database Migration Service Client for Node.js
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
-
Error: AuthNFailed - The client could not be authenticated.
cause Incorrect OCI configuration file (`~/.oci/config`), invalid API key fingerprint, private key path mismatch, or incorrect user/tenancy OCIDs.fixVerify all details in your `~/.oci/config` file. Ensure the private key file exists at the specified path and has correct permissions. Confirm the public key for the fingerprint is uploaded to your OCI user's API Keys. -
Error: 401 Unauthorized or 404 Not Found (specific resource, but general auth/permission issue)
cause The OCI user attempting the API call lacks the necessary IAM permissions for the resource or action, or the resource does not exist in the specified compartment/region for that user.fixCheck OCI IAM policies for the user and group. Ensure the policy grants `manage databasemigration-family` or specific verbs/resources within the compartment. Also, double-check the OCID of the resource and compartment. -
TypeError: Cannot read properties of undefined (reading 'DatabaseMigrationClient')
cause Incorrect import statement. The client class is not directly exported but accessed via the `databasemigration` namespace.fixChange `import { DatabaseMigrationClient } from 'oci-databasemigration';` to `import * as databasemigration from 'oci-databasemigration';` and then use `new databasemigration.DatabaseMigrationClient({...});`. -
Error: Region 'us-phoenix-1' is not a valid region. Valid regions are: ...
cause The specified OCI region in the client configuration or environment is misspelled, unsupported, or incorrect for the OCI realm.fixCorrect the region name. Ensure it matches one of the valid regions listed in the error message or the OCI documentation for the service. For `ConfigFileAuthenticationDetailsProvider`, check the `region` setting in `~/.oci/config`.
Warnings
- gotcha OCI SDKs heavily rely on a local configuration file (`~/.oci/config`) and API signing key pairs for authentication. Misconfiguration of this file or incorrect key pair setup is the most common cause of authentication failures.
- gotcha The `oci-databasemigration` package is a service-specific module. For full functionality, it depends on `oci-common` for shared utilities like authentication providers, retry mechanisms, and general OCI types. While `npm install oci-databasemigration` should pull `oci-common` as a dependency, explicitly understanding this relationship is crucial for debugging.
- gotcha OCI SDKs typically expect region to be explicitly set in the client configuration, or derived from the `authenticationDetailsProvider`. Using a mismatched region or an invalid region can lead to 'Not Found' or 'Unauthorized' errors, or even silent failures if the API endpoint doesn't exist in that region.
- breaking While no specific breaking changes were noted in the provided recent release logs, the OCI SDKs follow the general API versioning of OCI services. Major breaking changes are typically communicated through explicit version bumps in the service-specific modules. Developers should review release notes for significant version updates.
Install
-
npm install oci-databasemigration -
yarn add oci-databasemigration -
pnpm add oci-databasemigration
Imports
- DatabaseMigrationClient
import { DatabaseMigrationClient } from 'oci-databasemigration';import * as databasemigration from 'oci-databasemigration'; const client = new databasemigration.DatabaseMigrationClient({...}); - common.ConfigFileAuthenticationDetailsProvider
import { ConfigFileAuthenticationDetailsProvider } from 'oci-databasemigration';import * as common from 'oci-common'; const provider = new common.ConfigFileAuthenticationDetailsProvider();
- requests.ListMigrationsRequest
import { ListMigrationsRequest } from 'oci-databasemigration/lib/request';import * as databasemigration from 'oci-databasemigration'; const request: databasemigration.requests.ListMigrationsRequest = { compartmentId: '...' };
Quickstart
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();