lib/prick/constants.rb in prick-0.4.0 vs lib/prick/constants.rb in prick-0.5.0

- old
+ new

@@ -1,80 +1,92 @@ module Prick ### DIRECTORIES AND FILE NAMES - # Path to the .prick-version file - PRICK_VERSION_FILE = ".prick-version" - - # State files - PROJECT_STATE_FILE = ".prick-project" - FEATURES_STATE_FILE = ".prick-features" - MIGRATION_STATE_FILE = ".prick-migration" - MIGRATIONS_FILE = "migrations.sql" - - # Diff file - DIFF_FILE = "diff.sql" - # Shared files (part of the installation) SHARE_PATH = "#{File.dirname(File.dirname(__dir__))}/share" LIBEXEC_PATH = "#{File.dirname(File.dirname(__dir__))}/libexec" - STRIP_COMMENTS_COMMAND = File.join(LIBEXEC_PATH, "strip-comments") - # Project directories DIRS = [ - MIGRATIONS_DIR = "migrations", - RELEASES_DIR = "releases", - SCHEMAS_DIR = "schemas", - PRICK_DIR = "#{SCHEMAS_DIR}/prick", - PUBLIC_DIR = "#{SCHEMAS_DIR}/public", + MIGRATION_DIR = "migration", + SCHEMA_DIR = "schema", + PRICK_DIR = "#{SCHEMA_DIR}/prick", + PUBLIC_DIR = "#{SCHEMA_DIR}/public", VAR_DIR = "var", CACHE_DIR = "#{VAR_DIR}/cache", SPOOL_DIR = "#{VAR_DIR}/spool", TMP_DIR = "tmp", CLONE_DIR = "tmp/clone", SPEC_DIR = "spec" ] - # Path to prick data file -# PRICK_DATA_PATH = File.join(SCHEMAS_DIR, "prick", "data.sql") - SCHEMA_VERSION_PATH = File.join(SCHEMAS_DIR, "prick", "data.sql") + # The project state file + PROJECT_STATE_FILE = ".prick-project" + PROJECT_STATE_PATH = PROJECT_STATE_FILE + # The .prick-version file + PRICK_VERSION_FILE = ".prick-version" + PRICK_VERSION_PATH = PRICK_VERSION_FILE + + # The prick.versions data file. This is where the Schema saves its version + SCHEMA_VERSION_FILE = "data.sql" + SCHEMA_VERSION_PATH = File.join(PRICK_DIR, SCHEMA_VERSION_FILE) + + # The the .prick-migration file + PRICK_MIGRATION_FILE = ".prick-migration" + PRICK_MIGRATION_PATH = File.join(MIGRATION_DIR, PRICK_MIGRATION_FILE) + + # The the .prick-feature file + PRICK_FEATURE_FILE = ".prick-feature" + PRICK_FEATURE_PATH = File.join(MIGRATION_DIR, PRICK_FEATURE_FILE) + + # The strip-comments executable + STRIP_COMMENTS_NAME = "strip-comments" + STRIP_COMMENTS_PATH = File.join(LIBEXEC_PATH, "strip-comments") + + # Diff files + DIFF_FILE = "diff.sql" + BEFORE_TABLES_DIFF_NAME = "diff.before-tables.sql" + TABLES_DIFF_NAME = "diff.tables.sql" + AFTER_TABLES_DIFF_NAME = "diff.after-tables.sql" + + BEFORE_TABLES_DIFF_PATH = File.join(MIGRATION_DIR, BEFORE_TABLES_DIFF_NAME) + TABLES_DIFF_PATH = File.join(MIGRATION_DIR, TABLES_DIFF_NAME) + AFTER_TABLES_DIFF_PATH = File.join(MIGRATION_DIR, AFTER_TABLES_DIFF_NAME) + + TABLES_DIFF_SHARE_PATH = File.join(SHARE_PATH, "diff", TABLES_DIFF_NAME) + + # Dump files DUMP_EXT = "dump.gz" DUMP_GLOB = "*-[0-9]*.#{DUMP_EXT}" def self.dump_glob(project_name) "#{project_name}-*.#{DUMP_EXT}" end ### REGULAR EXPRESSIONS + # Matches a system name. System names are used for objects that are external to prick + # (like usernames) + NAME_SUB_RE = /[a-z][a-z0-9_-]*/ + NAME_RE = /^#{NAME_SUB_RE}$/ + # Matches an identifier. Identifiers consist of lower case letters, digits # and underscores but not dashes because they're used as separators IDENT_SUB_RE = /[a-z][a-z0-9_]*/ IDENT_RE = /^#{IDENT_SUB_RE}$/ - # Matches an uppercase identifier -# UPCASE_IDENT_SUB_RE = /[A-Z][A-Z0-9_]*/ -# UPCASE_IDENT_RE = /#{UPCASE_IDENT_SUB_RE}/ - - # A (system) name. Names are used for projects and usernames that are - # external to prick and can include both dashes and underscores but dashes - # have to be followed by a character and not a digit so 'ident-1234' is not - # allowed but 'ident_1234' and 'ident1234' are - NAME_SUB_RE = /#{IDENT_SUB_RE}/ - NAME_RE = /^#{NAME_SUB_RE}$/ - # Matches a project name - PROJECT_NAME_SUB_RE = NAME_SUB_RE - PROJECT_NAME_RE = NAME_RE + PROJECT_NAME_SUB_RE = IDENT_SUB_RE + PROJECT_NAME_RE = IDENT_RE # Matches a custom name - CUSTOM_NAME_SUB_RE = NAME_SUB_RE - CUSTOM_NAME_RE = NAME_RE + CUSTOM_NAME_SUB_RE = IDENT_SUB_RE + CUSTOM_NAME_RE = IDENT_RE # Matches a feature name - FEATURE_NAME_SUB_RE = NAME_SUB_RE - FEATURE_NAME_RE = NAME_RE + FEATURE_NAME_SUB_RE = /(?!initial)#{IDENT_SUB_RE}/ + FEATURE_NAME_RE = /^#{FEATURE_NAME_SUB_RE}$/ # Matches a postgres user name USER_NAME_SUB_RE = NAME_SUB_RE USER_NAME_RE = NAME_RE @@ -101,19 +113,52 @@ # Matches a semantic version # SEMVER_SUB_RE = /#{MMP_SEMVER_SUB_RE}(?:-#{PRE_SEMVER_SUB_RE})?/ SEMVER_RE = /^#{SEMVER_SUB_RE}$/ - # Version RE. The general syntax for a version is '<custom>-<version>_<feature>' + # Tag RE. The general syntax for a tag is '<custom>-v<version>_<feature>' # # The RE defines the following captures: # $1 - custom name, can be nil # $2 - semantic version # $3 - feature name, can be nil # + TAG_SUB_RE = / + (?:(#{CUSTOM_NAME_SUB_RE})-)? + v + (#{SEMVER_SUB_RE}) + (?:_(#{FEATURE_NAME_SUB_RE}))? + /x + TAG_RE = /^#{TAG_SUB_RE}$/ + + # TODO: Handle initial branches (0.0.0-initial) + + # Branch RE. The general syntax for a branch is '<custom>-<version>_<feature>' + # + # The RE defines the following captures: + # $1 - custom name, can be nil + # $2 - semantic version + # $3 - feature name, can be nil + # + BRANCH_SUB_RE = / + (?:(#{CUSTOM_NAME_SUB_RE})-)? + (#{SEMVER_SUB_RE}) + (?:_(#{FEATURE_NAME_SUB_RE}))? + /x + BRANCH_RE = /^#{BRANCH_SUB_RE}$/ + + # Tag or branch RE. The general syntax for a branch is '<custom>-v?<version>_<feature>' + # + # The RE defines the following captures: + # $1 - custom name, can be nil + # $2 - tag, nil or 'v' + # $3 - semantic version + # $4 - feature name, can be nil + # VERSION_SUB_RE = / (?:(#{CUSTOM_NAME_SUB_RE})-)? + (v)? (#{SEMVER_SUB_RE}) (?:_(#{FEATURE_NAME_SUB_RE}))? /x VERSION_RE = /^#{VERSION_SUB_RE}$/ @@ -133,37 +178,37 @@ # # The RE defines the following captures: # $1 - custom name, can be nil # $2 - semantic version # - RELEASE_SUB_RE = / - (?:(#{CUSTOM_NAME_SUB_RE})-)? - (#{MMP_SEMVER_SUB_RE}) - /x - RELEASE_RE = /^#{RELEASE_SUB_RE}$/ +# RELEASE_SUB_RE = / +# (?:(#{CUSTOM_NAME_SUB_RE})-)? +# (#{MMP_SEMVER_SUB_RE}) +# /x +# RELEASE_RE = /^#{RELEASE_SUB_RE}$/ # Matches a prerelease branch # # The RE defines the following captures: # $1 - custom name, can be nil # $2 - semantic version # - PRERELEASE_SUB_RE = / - (?:(#{CUSTOM_NAME_SUB_RE})-)? - (#{MMP_SEMVER_SUB_RE}-#{PRE_SEMVER_SUB_RE}) - /x - PRERELEASE_RE = /^#{PRERELEASE_SUB_RE}$/ +# PRERELEASE_SUB_RE = / +# (?:(#{CUSTOM_NAME_SUB_RE})-)? +# (#{MMP_SEMVER_SUB_RE}-#{PRE_SEMVER_SUB_RE}) +# /x +# PRERELEASE_RE = /^#{PRERELEASE_SUB_RE}$/ # Matches a feature branch # # The RE defines the following captures: # $1 - custom name, can be nil # $2 - semantic version # $3 - feature name # - FEATURE_SUB_RE = /#{ABSTRACT_RELEASE_SUB_RE}_(#{FEATURE_NAME_SUB_RE})/ - FEATURE_RE = /^#{FEATURE_SUB_RE}$/ +# FEATURE_SUB_RE = /#{ABSTRACT_RELEASE_SUB_RE}_(#{FEATURE_NAME_SUB_RE})/ +# FEATURE_RE = /^#{FEATURE_SUB_RE}$/ # Migration RE. The syntax is <version>_<version> # # The RE defines the following captures # $1 - from version @@ -171,12 +216,12 @@ # $3 - from semantic version # $4 - to version # $5 - to custom name, can be nil # $6 - to semantic version # - MIGRATION_SUB_RE = /(#{RELEASE_SUB_RE})_(#{RELEASE_SUB_RE})/ - MIGRATION_RE = /^#{MIGRATION_SUB_RE}$/ +# MIGRATION_SUB_RE = /(#{RELEASE_SUB_RE})_(#{RELEASE_SUB_RE})/ +# MIGRATION_RE = /^#{MIGRATION_SUB_RE}$/ # Project release RE. The general syntax is '<project>-<custom>-<version>' # # The RE defines the following captures: # $1 - project @@ -215,7 +260,14 @@ # ALL_DATABASES_SUB_RE = /(#{PROJECT_NAME_SUB_RE})(?:-(#{ABSTRACT_RELEASE_SUB_RE}))?/ ALL_DATABASES_RE = /^#{ALL_DATABASES_SUB_RE}$/ def self.all_databases_sub_re(project_name) /(#{project_name})(?:-(#{ABSTRACT_RELEASE_SUB_RE}))?/ end def self.all_databases_re(project_name) /^#{all_databases_sub_re(project_name)}$/ end + + # Matches temporary databases. Mostly useful when debugging because temporary databases + # should be deleted on exit + TMP_DATABASES_SUB_RE = /#{PROJECT_NAME_SUB_RE}-(?:base|next)/ + TMP_DATABASES_RE = /^#{TMP_DATABASES_SUB_RE}$/ + def self.tmp_databases_sub_re(project_name) /#{project_name}-(?:base|next)/ end + def self.tmp_databases_re(project_name) /^#{tmp_databases_sub_re(project_name)}$/ end end