Skip to content

Commit

Permalink
shortlnik-link: refactoring migration
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Login <batazor@evrone.com>
  • Loading branch information
batazor committed Jun 7, 2023
1 parent a232ebf commit 3016129
Show file tree
Hide file tree
Showing 26 changed files with 21 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DROP TABLE IF EXISTS links;
DROP TABLE IF EXISTS shortlink.links;
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

-- ShortLink Schema ====================================================================================================

CREATE SCHEMA IF NOT EXISTS shortlink;

COMMENT ON SCHEMA shortlink IS 'Shortlink schema';

-- Create a table for links
CREATE TABLE links
CREATE TABLE shortlink.links
(
id UUID NOT NULL DEFAULT uuid_generate_v4(),
CONSTRAINT id_links PRIMARY KEY(id),
Expand All @@ -11,14 +17,14 @@ CREATE TABLE links
json jsonb not null
) WITH (fillfactor = 100);

COMMENT ON TABLE links IS 'Link list';
COMMENT ON TABLE shortlink.links IS 'Link list';

CREATE UNIQUE INDEX links_id_uindex
ON links (id);
ON shortlink.links (id);

CREATE UNIQUE INDEX links_hash_uindex
ON links (hash);
ON shortlink.links (hash);

-- INCLUDE-index
-- as example: SELECT id, url, hash FROM links WHERE id = 10;
CREATE UNIQUE INDEX links_list ON links USING btree (hash) INCLUDE (url);
CREATE UNIQUE INDEX links_list ON shortlink.links USING btree (hash) INCLUDE (url);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BEGIN
ISOLATION LEVEL READ COMMITTED;

DELETE FROM links
DELETE FROM shortlink.links
WHERE hash IN ("myHash1", "myHash2", "myHash3")

COMMIT;
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ BEGIN

SAVEPOINT tx_create_default_links;

INSERT INTO links(url, hash, describe, json)
INSERT INTO shortlink.links(url, hash, describe, json)
VALUES ('https://batazor.ru', 'myHash1', 'My personal website', '{"url":"https://batazor.ru", "hash":"myHash1","describe":"My personal website"}');

INSERT INTO links(url, hash, describe, json)
INSERT INTO shortlink.links(url, hash, describe, json)
VALUES ('https://github.com/batazor', 'myHash2', 'My accout of github', '{"url":"https://github.com/batazor", "hash":"myHash2","describe":"My accout of github"}');

INSERT INTO links(url, hash, describe, json)
INSERT INTO shortlink.links(url, hash, describe, json)
VALUES ('https://vk.com/batazor', 'myHash3', 'My page on vk.com', '{"url":"https://vk.com/batazor", "hash":"myHash3","describe":"My page on vk.com"}');

-- ROLLBACK TO tx_create_default_links;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BEGIN
ISOLATION LEVEL READ COMMITTED;

ALTER TABLE links DROP COLUMN created_at;
ALTER TABLE links DROP COLUMN updated_at;
ALTER TABLE shortlink.links DROP COLUMN created_at;
ALTER TABLE shortlink.links DROP COLUMN updated_at;

COMMIT;
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
BEGIN
ISOLATION LEVEL READ COMMITTED;

ALTER TABLE links
ALTER TABLE shortlink.links
ADD created_at TIMESTAMP DEFAULT current_timestamp;

ALTER TABLE links
ALTER TABLE shortlink.links
ADD updated_at TIMESTAMP DEFAULT current_timestamp;

COMMIT;
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
-- ShortLink Schema ====================================================================================================

CREATE SCHEMA IF NOT EXISTS shortlink;

COMMENT ON SCHEMA shortlink IS 'Shortlink schema';

-- CQRS for links ======================================================================================================
CREATE TABLE shortlink.link_view
(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE EXTENSION IF NOT EXISTS pg_prewarm;

This file was deleted.

Empty file.

0 comments on commit 3016129

Please sign in to comment.