@clickup/pg-mig
Version:
PostgreSQL schema migration tool with microsharding and clustering support
21 lines (20 loc) • 606 B
text/typescript
/**
* See unit test for matching and non-matching examples.
*/
export function schemaNameMatchesPrefix(
schema: string,
prefix: string,
): boolean {
const schemaStartsWithPrefix = schema.startsWith(prefix);
const schemaEqualsToPrefixExactly = schema === prefix;
const schemaHasDigitAfterPrefix = schema
.substring(prefix.length)
.match(/^\d/);
const prefixItselfHasDigitSoItIsSelectiveEnough = prefix.match(/\d/);
return !!(
schemaStartsWithPrefix &&
(schemaEqualsToPrefixExactly ||
schemaHasDigitAfterPrefix ||
prefixItselfHasDigitSoItIsSelectiveEnough)
);
}