diff --git a/schema/000_extensions.sql b/schema/000_extensions.sql new file mode 100644 index 0000000..436ab0f --- /dev/null +++ b/schema/000_extensions.sql @@ -0,0 +1 @@ +create extension pgcrypto; diff --git a/schema/000_hashed_text.sql b/schema/000_hashed_text.sql deleted file mode 100644 index c3ebb9c..0000000 --- a/schema/000_hashed_text.sql +++ /dev/null @@ -1 +0,0 @@ -create type hashed_text as (hashed text); diff --git a/schema/000_email.sql b/schema/010_email.sql similarity index 100% rename from schema/000_email.sql rename to schema/010_email.sql diff --git a/schema/010_hashed_text.sql b/schema/010_hashed_text.sql new file mode 100644 index 0000000..1cde164 --- /dev/null +++ b/schema/010_hashed_text.sql @@ -0,0 +1,27 @@ +create type hashed_text as (hashed text); + +create function hashed_text_string(hashed hashed_text) + returns text + language sql + immutable + as 'select (hashed.hashed);'; + +create function hash_text(plain text) + returns hashed_text + language plpgsql + immutable + as $$ +begin + return row(crypt(plain, gen_salt('bf'))); +end; +$$; + +create function hashed_text_matches(plain text, hashed hashed_text) + returns boolean + language plpgsql + immutable + as $$ +begin + return hashed_text_string(hashed) = crypt(plain, hashed_text_string(hashed)); +end; +$$; diff --git a/schema/010_audit.sql b/schema/020_audit.sql similarity index 100% rename from schema/010_audit.sql rename to schema/020_audit.sql diff --git a/schema/010_thread.sql b/schema/020_thread.sql similarity index 100% rename from schema/010_thread.sql rename to schema/020_thread.sql diff --git a/schema/010_user.sql b/schema/020_user.sql similarity index 100% rename from schema/010_user.sql rename to schema/020_user.sql