Skip to content

Commit

Permalink
Let script_hash be NULL.
Browse files Browse the repository at this point in the history
Because it is allowed to have a change with no deploy script!
  • Loading branch information
theory committed Jan 6, 2015
1 parent a04be11 commit 2421b75
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 34 deletions.
12 changes: 2 additions & 10 deletions lib/App/Sqitch/Engine/Upgrade/firebird-1.0.sql
Expand Up @@ -25,16 +25,8 @@ UPDATE RDB$RELATION_FIELDS
SET RDB$DESCRIPTION = 'Email address of the user who installed the registry release.'
WHERE RDB$RELATION_NAME = 'VERSIONS' AND RDB$FIELD_NAME = 'INSTALLER_EMAIL';

-- Add the script_hash column to the changes table. Copy change_id for now.
ALTER TABLE changes ADD script_hash VARCHAR(40);
UPDATE changes SET script_hash = change_id;

-- Make the column NOT NULL UNIQUE.
UPDATE RDB$RELATION_FIELDS SET RDB$NULL_FLAG = 1
WHERE RDB$RELATION_NAME = 'CHANGES' AND RDB$FIELD_NAME = 'SCRIPT_HASH';
ALTER TABLE changes ADD CONSTRAINT UNIQUE (script_hash);

-- Add a comment on the new column.
-- Add the script_hash column to the changes table.
ALTER TABLE changes ADD script_hash VARCHAR(40) NULL UNIQUE;
UPDATE RDB$RELATION_FIELDS
SET RDB$DESCRIPTION = 'Deploy script SHA-1 hash.'
WHERE RDB$RELATION_NAME = 'CHANGES' AND RDB$FIELD_NAME = 'SCRIPT_HASH';
4 changes: 1 addition & 3 deletions lib/App/Sqitch/Engine/Upgrade/mysql-1.0.sql
Expand Up @@ -13,6 +13,4 @@ CREATE TABLE releases (
;

-- Add the script_hash column to the changes table. Copy change_id for now.
ALTER TABLE changes ADD COLUMN script_hash VARCHAR(40);
UPDATE changes SET script_hash = change_id;
ALTER TABLE changes MODIFY script_hash VARCHAR(40) NOT NULL UNIQUE;
ALTER TABLE changes ADD COLUMN script_hash VARCHAR(40) NULL UNIQUE;
4 changes: 1 addition & 3 deletions lib/App/Sqitch/Engine/Upgrade/oracle-1.0.sql
Expand Up @@ -12,7 +12,5 @@ COMMENT ON COLUMN &registry..releases.installer_name IS 'Name of the user who i
COMMENT ON COLUMN &registry..releases.installer_email IS 'Email address of the user who installed the registry release.';

-- Add the script_hash column to the changes table. Copy change_id for now.
ALTER TABLE &registry..changes ADD script_hash CHAR(40);
UPDATE &registry..changes SET script_hash = change_id;
ALTER TABLE &registry..changes MODIFY (script_hash NOT NULL UNIQUE);
ALTER TABLE &registry..changes ADD script_hash CHAR(40) NULL UNIQUE;
COMMENT ON COLUMN &registry..changes.script_hash IS 'Deploy script SHA-1 hash.';
5 changes: 1 addition & 4 deletions lib/App/Sqitch/Engine/Upgrade/pg-1.0.sql
Expand Up @@ -16,10 +16,7 @@ COMMENT ON COLUMN :"registry".releases.installer_name IS 'Name of the user who
COMMENT ON COLUMN :"registry".releases.installer_email IS 'Email address of the user who installed the registry release.';

-- Add the script_hash column to the changes table. Copy change_id for now.
ALTER TABLE :"registry".changes ADD COLUMN script_hash TEXT;
UPDATE :"registry".changes SET script_hash = change_id;
ALTER TABLE :"registry".changes ALTER COLUMN script_hash SET NOT NULL;
ALTER TABLE :"registry".changes ADD CONSTRAINT changes_script_hash_key UNIQUE (script_hash);
ALTER TABLE :"registry".changes ADD COLUMN script_hash TEXT NULL UNIQUE;
COMMENT ON COLUMN :"registry".changes.script_hash IS 'Deploy script SHA-1 hash.';

COMMIT;
4 changes: 2 additions & 2 deletions lib/App/Sqitch/Engine/Upgrade/sqlite-1.0.sql
Expand Up @@ -10,7 +10,7 @@ CREATE TABLE releases (
-- Create a new changes table with script_hash.
CREATE TABLE new_changes (
change_id TEXT PRIMARY KEY,
script_hash TEXT NOT NULL UNIQUE,
script_hash TEXT NULL UNIQUE,
change TEXT NOT NULL,
project TEXT NOT NULL REFERENCES projects(project) ON UPDATE CASCADE,
note TEXT NOT NULL DEFAULT '',
Expand All @@ -24,7 +24,7 @@ CREATE TABLE new_changes (

-- Copy all the data to the new table and move it into place.
INSERT INTO new_changes
SELECT change_id, change_id, change, project, note,
SELECT change_id, NULL, change, project, note,
committed_at, committer_name, committer_email,
planned_at, planner_name, planner_email
FROM changes;
Expand Down
5 changes: 1 addition & 4 deletions lib/App/Sqitch/Engine/Upgrade/vertica-1.0.sql
Expand Up @@ -8,7 +8,4 @@ CREATE TABLE :"registry".releases (
COMMENT ON TABLE :"registry".releases IS 'Sqitch registry releases.';

-- Add the script_hash column to the changes table. Copy change_id for now.
ALTER TABLE :"registry".changes ADD COLUMN script_hash CHAR(40);
UPDATE :"registry".changes SET script_hash = change_id;
ALTER TABLE :"registry".changes ALTER COLUMN script_hash SET NOT NULL;
ALTER TABLE :"registry".changes ADD CONSTRAINT changes_script_hash_key UNIQUE (script_hash);
ALTER TABLE :"registry".changes ADD COLUMN script_hash CHAR(40) NULL UNIQUE;
2 changes: 1 addition & 1 deletion lib/App/Sqitch/Engine/firebird.sql
Expand Up @@ -76,7 +76,7 @@ UPDATE RDB$RELATION_FIELDS

CREATE TABLE changes (
change_id VARCHAR(40) NOT NULL PRIMARY KEY,
script_hash VARCHAR(40) NOT NULL UNIQUE,
script_hash VARCHAR(40) NULL UNIQUE,
change VARCHAR(255) NOT NULL,
project VARCHAR(255) NOT NULL REFERENCES projects(project)
ON UPDATE CASCADE,
Expand Down
2 changes: 1 addition & 1 deletion lib/App/Sqitch/Engine/mysql.sql
Expand Up @@ -35,7 +35,7 @@ CREATE TABLE projects (
CREATE TABLE changes (
change_id VARCHAR(40) PRIMARY KEY
COMMENT 'Change primary key.',
script_hash VARCHAR(40) NOT NULL UNIQUE
script_hash VARCHAR(40) NULL UNIQUE
COMMENT 'Deploy script SHA-1 hash.',
"change" VARCHAR(255) NOT NULL
COMMENT 'Name of a deployed change.',
Expand Down
2 changes: 1 addition & 1 deletion lib/App/Sqitch/Engine/oracle.sql
Expand Up @@ -28,7 +28,7 @@ COMMENT ON COLUMN &registry..projects.creator_email IS 'Email address of the us

CREATE TABLE &registry..changes (
change_id CHAR(40) PRIMARY KEY,
script_hash CHAR(40) NOT NULL UNIQUE,
script_hash CHAR(40) NULL UNIQUE,
change VARCHAR2(512 CHAR) NOT NULL,
project VARCHAR2(512 CHAR) NOT NULL REFERENCES &registry..projects(project),
note VARCHAR2(4000 CHAR) DEFAULT '',
Expand Down
2 changes: 1 addition & 1 deletion lib/App/Sqitch/Engine/pg.sql
Expand Up @@ -35,7 +35,7 @@ COMMENT ON COLUMN :"registry".projects.creator_email IS 'Email address of the u

CREATE TABLE :"registry".changes (
change_id TEXT PRIMARY KEY,
script_hash TEXT NOT NULL UNIQUE,
script_hash TEXT NULL UNIQUE,
change TEXT NOT NULL,
project TEXT NOT NULL REFERENCES :"registry".projects(project) ON UPDATE CASCADE,
note TEXT NOT NULL DEFAULT '',
Expand Down
2 changes: 1 addition & 1 deletion lib/App/Sqitch/Engine/sqlite.sql
Expand Up @@ -17,7 +17,7 @@ CREATE TABLE projects (

CREATE TABLE changes (
change_id TEXT PRIMARY KEY,
script_hash TEXT NOT NULL UNIQUE,
script_hash TEXT NULL UNIQUE,
change TEXT NOT NULL,
project TEXT NOT NULL REFERENCES projects(project) ON UPDATE CASCADE,
note TEXT NOT NULL DEFAULT '',
Expand Down
2 changes: 1 addition & 1 deletion lib/App/Sqitch/Plan/Change.pm
Expand Up @@ -202,7 +202,7 @@ sub deploy_file {

sub script_hash {
my $path = shift->deploy_file;
return '0000000000000000000000000000000000000000' unless -e $path;
return undef unless -f $path;
require Digest::SHA;
my $sha = Digest::SHA->new(1);
$sha->add( $path->slurp(iomode => '<:raw') );
Expand Down
4 changes: 2 additions & 2 deletions t/change.t
Expand Up @@ -109,8 +109,8 @@ is_deeply [ $change->path_segments ], ['foo.sql'],
'path_segments should not include suffix';

# Test script_hash.
is $change->script_hash, '0000000000000000000000000000000000000000',
'Nonexistent deploy script hash should be null hash';
is $change->script_hash, undef,
'Nonexistent deploy script hash should be undef';
make_path $change->deploy_file->dir->stringify;
$change->deploy_file->spew(iomode => '>:utf8', "Foo\nBar\nBøz\n亜唖娃阿" );
is $change->script_hash, 'd48866b846300912570f643c99b2ceec4ba29f5c',
Expand Down

0 comments on commit 2421b75

Please sign in to comment.