Package org.pgcodekeeper.core.api
Class PgCodeKeeperApi
java.lang.Object
org.pgcodekeeper.core.api.PgCodeKeeperApi
Main API class for pgCodeKeeper database operations.
-
Method Summary
Modifier and TypeMethodDescriptionanalyzeDependencies(ILoader loader, Collection<String> objectNames, int depth, boolean reverse, Collection<DbObjType> filterTypes, boolean invertFilter) Analyzes database object dependencies and builds a dependency graph.static Set<DangerStatement>checkDangerousStatements(IDatabaseProvider provider, String name, String sql, DiffSettings diffSettings, Collection<DangerStatement> allowedDangers) Checks SQL script for dangerous operations (DROP TABLE, ALTER COLUMN, etc.).static TreeElementcreateTree(ILoader oldDbLoader, ILoader newDbLoader, DiffSettings diffSettings) Compares two databases and generates a tree.static Stringdiff(IDatabaseProvider provider, ILoader oldDbLoader, ILoader newDbLoader, DiffSettings diffSettings) Compares two databases and generates a migration script.static Stringdiff(IDatabaseProvider provider, IDatabase oldDb, IDatabase newDb, DiffSettings diffSettings) Compares two databases and generates a migration script.static Stringdiff(IDatabaseProvider provider, IDatabase oldDb, IDatabase newDb, DiffSettings diffSettings, TreeElement root) Compares two databases and generates a migration script with a pre-built tree.static voidexportToProject(IDatabaseProvider provider, ILoader oldDbLoader, ILoader newDbLoader, Path projectPath, boolean overridesOnly, DiffSettings diffSettings) Exports or updates project or overrides files based on database schema.static voidexportToProject(IDatabaseProvider provider, ILoader oldDbLoader, ILoader newDbLoader, Path projectPath, DiffSettings diffSettings) Exports or updates project files based on database schema.static voidexportToProject(IDatabaseProvider provider, IDatabase oldDb, IDatabase newDb, List<TreeElement> selected, Path projectPath, boolean overridesOnly, ISettings settings) Exports or updates project or overrides files based on selected elements.static voidrunSQL(IDatabaseProvider provider, String name, String sql, String url, DiffSettings diffSettings) Parses and executes SQL script against a database.
-
Method Details
-
createTree
public static TreeElement createTree(ILoader oldDbLoader, ILoader newDbLoader, DiffSettings diffSettings) throws IOException, InterruptedException Compares two databases and generates a tree.- Parameters:
oldDbLoader- loader for the old database version to compare fromnewDbLoader- loader for the new database version to compare todiffSettings- unified context object containing settings, ignore list, and error accumulator- Returns:
- the root element of generated tree
- Throws:
IOException- if I/O operations failInterruptedException- if the thread is interrupted during the operation
-
diff
public static String diff(IDatabaseProvider provider, ILoader oldDbLoader, ILoader newDbLoader, DiffSettings diffSettings) throws IOException, InterruptedException Compares two databases and generates a migration script.- Parameters:
provider- the database provider determining SQL dialectoldDbLoader- loader for the old database version to compare fromnewDbLoader- loader for the new database version to compare todiffSettings- unified context object containing settings, ignore list, and error accumulator- Returns:
- the generated migration script as a string
- Throws:
IOException- if I/O operations failInterruptedException- if the thread is interrupted during the operation
-
diff
public static String diff(IDatabaseProvider provider, IDatabase oldDb, IDatabase newDb, DiffSettings diffSettings) throws IOException, InterruptedException Compares two databases and generates a migration script.- Parameters:
provider- the database provider determining SQL dialectoldDb- the old database version to compare fromnewDb- the new database version to compare todiffSettings- unified context object containing settings, ignore list, and error accumulator- Returns:
- the generated migration script as a string
- Throws:
IOException- if I/O operations failInterruptedException- if the thread is interrupted during the operation
-
diff
public static String diff(IDatabaseProvider provider, IDatabase oldDb, IDatabase newDb, DiffSettings diffSettings, TreeElement root) throws IOException Compares two databases and generates a migration script with a pre-built tree.- Parameters:
provider- the database provider determining SQL dialectoldDb- the old database version to compare fromnewDb- the new database version to compare todiffSettings- unified context object containing settings, ignore list, and error accumulatorroot- root element of tree- Returns:
- the generated migration script as a string
- Throws:
IOException- if I/O operations fail
-
exportToProject
public static void exportToProject(IDatabaseProvider provider, ILoader oldDbLoader, ILoader newDbLoader, Path projectPath, DiffSettings diffSettings) throws IOException, InterruptedException Exports or updates project files based on database schema.If
oldDbisnull, exportsnewDbschema to an empty project directory. IfoldDbis provided, updates the existing project with changes betweenoldDbandnewDb.- Parameters:
provider- the database provider determining SQL dialect and exporter/updater implementationoldDbLoader- loader for the old database version (existing project state), ornullfor a full exportnewDbLoader- loader for the new new database version (target state)projectPath- path to the target project directorydiffSettings- unified context object containing settings, monitor, ignore list, and error accumulator- Throws:
IOException- if I/O operations fail, if the directory does not exist, if the directory is not empty (export) or if path is a fileInterruptedException- if the thread is interrupted during the operation
-
exportToProject
public static void exportToProject(IDatabaseProvider provider, ILoader oldDbLoader, ILoader newDbLoader, Path projectPath, boolean overridesOnly, DiffSettings diffSettings) throws IOException, InterruptedException Exports or updates project or overrides files based on database schema.If
oldDbisnull, exportsnewDbschema to an empty project directory. IfoldDbis provided, updates the existing project with changes betweenoldDbandnewDb.- Parameters:
provider- the database provider determining SQL dialect and exporter/updater implementationoldDbLoader- loader for the old database version (existing project state), ornullfor a full exportnewDbLoader- loader for the new new database version (target state)projectPath- path to the target project directoryoverridesOnly- option to update only overridesdiffSettings- unified context object containing settings, monitor, ignore list, and error accumulator- Throws:
IOException- if I/O operations fail, if the directory does not exist, if the directory is not empty (export) or if path is a fileInterruptedException- if the thread is interrupted during the operation
-
exportToProject
public static void exportToProject(IDatabaseProvider provider, IDatabase oldDb, IDatabase newDb, List<TreeElement> selected, Path projectPath, boolean overridesOnly, ISettings settings) throws IOException Exports or updates project or overrides files based on selected elements.- Parameters:
provider- the database provider determining SQL dialect and exporter/updater implementationoldDb- the old database version (existing project state), ornullfor a full exportnewDb- the new new database version (target state)selected- the selected elementsprojectPath- path to the target project directoryoverridesOnly- option to update only overridessettings- configuration settings- Throws:
IOException- if I/O operations fail, if the directory does not exist, if the directory is not empty (export) or if path is a file
-
analyzeDependencies
public static List<String> analyzeDependencies(ILoader loader, Collection<String> objectNames, int depth, boolean reverse, Collection<DbObjType> filterTypes, boolean invertFilter) throws IOException, InterruptedException Analyzes database object dependencies and builds a dependency graph.- Parameters:
loader- loader for the the database to analyzeobjectNames- collection of object name patterns to search for (e.g., "public.users", "*.orders")depth- depth of dependency analysis (e.g., 10 levels)reverse- false = direct dependencies (what this depends on), true = reverse dependencies (what depends on this)filterTypes- types of objects to filter (TABLE, FUNCTION, VIEW), null = all typesinvertFilter- false = include only specified types, true = exclude specified types- Returns:
- list of strings with dependency information
- Throws:
IOException- if I/O operations failInterruptedException- if the thread is interrupted during the operation
-
checkDangerousStatements
public static Set<DangerStatement> checkDangerousStatements(IDatabaseProvider provider, String name, String sql, DiffSettings diffSettings, Collection<DangerStatement> allowedDangers) throws IOException, InterruptedException Checks SQL script for dangerous operations (DROP TABLE, ALTER COLUMN, etc.).- Parameters:
provider- the database provider determining SQL dialectname- name of the script source (used as file identifier for parsing)sql- the SQL script to checkdiffSettings- parsing settingsallowedDangers- set of allowed dangerous operations- Returns:
- set of detected dangerous operations
- Throws:
IOException- if I/O operations failInterruptedException- if the thread is interrupted during the operation
-
runSQL
public static void runSQL(IDatabaseProvider provider, String name, String sql, String url, DiffSettings diffSettings) throws IOException, InterruptedException, SQLException Parses and executes SQL script against a database.- Parameters:
provider- the database provider determining SQL dialect and JDBC connectorname- name of the script source (used as file identifier for parsing)sql- the SQL script to executeurl- full JDBC URL of the target databasediffSettings- parsing and execution settings- Throws:
IOException- if there is an error reading the scriptInterruptedException- if the thread is interrupted during the operationSQLException- if a database access error occurs during execution
-