Skip to content

Commit

Permalink
Split solana slot migration (#2893)
Browse files Browse the repository at this point in the history
  • Loading branch information
jowlee committed Apr 11, 2022
1 parent ef27aad commit 95f3aa8
Show file tree
Hide file tree
Showing 5 changed files with 295 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,85 +42,6 @@ def upgrade():
ALTER TABLE users ALTER COLUMN blockhash DROP NOT NULL;
ALTER TABLE users ALTER COLUMN blocknumber DROP NOT NULL;
ALTER TABLE tracks DROP CONSTRAINT IF EXISTS tracks_pkey;
UPDATE tracks
SET txhash = ('unset_' || substr(md5(random()::text), 0, 10))
WHERE txhash='';
ALTER TABLE tracks ADD PRIMARY KEY (is_current, track_id, txhash);
ALTER TABLE tracks ADD COLUMN IF NOT EXISTS slot INTEGER;
-- Drop NOT NULL Constraint on POA blockhash and tx hash columns
ALTER TABLE tracks ALTER COLUMN blockhash DROP NOT NULL;
ALTER TABLE tracks ALTER COLUMN blocknumber DROP NOT NULL;
ALTER TABLE playlists DROP CONSTRAINT IF EXISTS playlists_pkey;
UPDATE playlists
SET txhash = ('unset_' || substr(md5(random()::text), 0, 10))
WHERE txhash='';
ALTER TABLE playlists ADD PRIMARY KEY (is_current, playlist_id, txhash);
ALTER TABLE playlists ADD COLUMN IF NOT EXISTS slot INTEGER;
-- Drop NOT NULL Constraint on POA blockhash and tx hash columns
ALTER TABLE playlists ALTER COLUMN blockhash DROP NOT NULL;
ALTER TABLE playlists ALTER COLUMN blocknumber DROP NOT NULL;
ALTER TABLE reposts DROP CONSTRAINT IF EXISTS reposts_pkey;
UPDATE reposts
SET txhash = ('unset_' || substr(md5(random()::text), 0, 10))
WHERE txhash='';
ALTER TABLE reposts ADD PRIMARY KEY (is_current, user_id, repost_item_id, repost_type, txhash);
ALTER TABLE reposts ADD COLUMN IF NOT EXISTS slot INTEGER;
-- Drop NOT NULL Constraint on POA blockhash and tx hash columns
ALTER TABLE reposts ALTER COLUMN blockhash DROP NOT NULL;
ALTER TABLE reposts ALTER COLUMN blocknumber DROP NOT NULL;
ALTER TABLE saves DROP CONSTRAINT IF EXISTS saves_pkey;
UPDATE saves
SET txhash = ('unset_' || substr(md5(random()::text), 0, 10))
WHERE txhash='';
ALTER TABLE saves ADD PRIMARY KEY (is_current, user_id, save_item_id, save_type, txhash);
ALTER TABLE saves ADD COLUMN IF NOT EXISTS slot INTEGER;
-- Drop NOT NULL Constraint on POA blockhash and tx hash columns
ALTER TABLE saves ALTER COLUMN blockhash DROP NOT NULL;
ALTER TABLE saves ALTER COLUMN blocknumber DROP NOT NULL;
ALTER TABLE ursm_content_nodes DROP CONSTRAINT IF EXISTS ursm_content_nodes_pkey;
UPDATE ursm_content_nodes
SET txhash = ('unset_' || substr(md5(random()::text), 0, 10))
WHERE txhash='';
ALTER TABLE ursm_content_nodes ADD PRIMARY KEY (is_current, cnode_sp_id, txhash);
ALTER TABLE ursm_content_nodes ADD COLUMN IF NOT EXISTS slot INTEGER;
-- Drop NOT NULL Constraint on POA blockhash and tx hash columns
ALTER TABLE ursm_content_nodes ALTER COLUMN blockhash DROP NOT NULL;
ALTER TABLE ursm_content_nodes ALTER COLUMN blocknumber DROP NOT NULL;
ALTER TABLE follows DROP CONSTRAINT IF EXISTS follows_pkey;
UPDATE follows
SET txhash = ('unset_' || substr(md5(random()::text), 0, 10))
WHERE txhash='';
ALTER TABLE follows ADD PRIMARY KEY (is_current, follower_user_id, followee_user_id, txhash);
ALTER TABLE follows ADD COLUMN IF NOT EXISTS slot INTEGER;
-- Drop NOT NULL Constraint on POA blockhash and tx hash columns
ALTER TABLE follows ALTER COLUMN blockhash DROP NOT NULL;
ALTER TABLE follows ALTER COLUMN blocknumber DROP NOT NULL;
-- Drop NOT NULL Constraint on POA blockhash and tx hash columns
ALTER TABLE user_events ADD COLUMN IF NOT EXISTS slot INTEGER;
ALTER TABLE user_events ALTER COLUMN blockhash DROP NOT NULL;
ALTER TABLE user_events ALTER COLUMN blocknumber DROP NOT NULL;
commit;
"""
)
Expand All @@ -147,71 +68,6 @@ def downgrade():
ALTER TABLE users ALTER COLUMN blockhash SET NOT NULL;
ALTER TABLE users ALTER COLUMN blocknumber SET NOT NULL;
ALTER TABLE tracks DROP CONSTRAINT IF EXISTS tracks_pkey;
ALTER TABLE tracks ADD PRIMARY KEY (is_current, track_id, blockhash, txhash);
ALTER TABLE tracks DROP COLUMN IF EXISTS slot;
-- Add NOT NULL Constraint on POA blockhash and tx hash columns
DELETE FROM tracks where blockhash IS NULL or blocknumber IS NULL;
ALTER TABLE tracks ALTER COLUMN blockhash SET NOT NULL;
ALTER TABLE tracks ALTER COLUMN blocknumber SET NOT NULL;
ALTER TABLE playlists DROP CONSTRAINT IF EXISTS playlists_pkey;
ALTER TABLE playlists ADD PRIMARY KEY (is_current, playlist_id, playlist_owner_id, blockhash, txhash);
ALTER TABLE playlists DROP COLUMN IF EXISTS slot;
-- Add NOT NULL Constraint on POA blockhash and tx hash columns
DELETE FROM playlists where blockhash IS NULL or blocknumber IS NULL;
ALTER TABLE playlists ALTER COLUMN blockhash SET NOT NULL;
ALTER TABLE playlists ALTER COLUMN blocknumber SET NOT NULL;
ALTER TABLE reposts DROP CONSTRAINT IF EXISTS reposts_pkey;
ALTER TABLE reposts ADD PRIMARY KEY (is_current, user_id, repost_item_id, repost_type, blockhash, txhash);
ALTER TABLE reposts DROP COLUMN IF EXISTS slot;
-- Add NOT NULL Constraint on POA blockhash and tx hash columns
DELETE FROM reposts where blockhash IS NULL or blocknumber IS NULL;
ALTER TABLE reposts ALTER COLUMN blockhash SET NOT NULL;
ALTER TABLE reposts ALTER COLUMN blocknumber SET NOT NULL;
ALTER TABLE saves DROP CONSTRAINT IF EXISTS saves_pkey;
ALTER TABLE saves ADD PRIMARY KEY (is_current, user_id, save_item_id, save_type, blockhash, txhash);
ALTER TABLE saves DROP COLUMN IF EXISTS slot;
-- Add NOT NULL Constraint on POA blockhash and tx hash columns
DELETE FROM saves where blockhash IS NULL or blocknumber IS NULL;
ALTER TABLE saves ALTER COLUMN blockhash SET NOT NULL;
ALTER TABLE saves ALTER COLUMN blocknumber SET NOT NULL;
ALTER TABLE ursm_content_nodes DROP CONSTRAINT IF EXISTS ursm_content_nodes_pkey;
ALTER TABLE ursm_content_nodes ADD PRIMARY KEY (is_current, cnode_sp_id, blockhash, txhash);
ALTER TABLE ursm_content_nodes DROP COLUMN IF EXISTS slot;
-- Add NOT NULL Constraint on POA blockhash and tx hash columns
DELETE FROM ursm_content_nodes where blockhash IS NULL or blocknumber IS NULL;
ALTER TABLE ursm_content_nodes ALTER COLUMN blockhash SET NOT NULL;
ALTER TABLE ursm_content_nodes ALTER COLUMN blocknumber SET NOT NULL;
ALTER TABLE follows DROP CONSTRAINT IF EXISTS follows_pkey;
ALTER TABLE follows ADD PRIMARY KEY (is_current, follower_user_id, followee_user_id, blockhash, txhash);
ALTER TABLE follows DROP COLUMN IF EXISTS slot;
-- Add NOT NULL Constraint on POA blockhash and tx hash columns
ALTER TABLE follows ALTER COLUMN blockhash SET NOT NULL;
ALTER TABLE follows ALTER COLUMN blocknumber SET NOT NULL;
-- Drop NOT NULL Constraint on POA blockhash and tx hash columns
ALTER TABLE user_events DROP COLUMN IF EXISTS slot;
ALTER TABLE user_events ALTER COLUMN blockhash SET NOT NULL;
ALTER TABLE user_events ALTER COLUMN blocknumber SET NOT NULL;
commit;
"""
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
"""solana slot follows
Revision ID: 2cfd17a60647
Revises: a9215207bb7c
Create Date: 2022-04-10 20:18:38.443308
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "2cfd17a60647"
down_revision = "a9215207bb7c"
branch_labels = None
depends_on = None


def upgrade():
connection = op.get_bind()
connection.execute(
"""
begin;
ALTER TABLE ursm_content_nodes DROP CONSTRAINT IF EXISTS ursm_content_nodes_pkey;
UPDATE ursm_content_nodes
SET txhash = ('unset_' || substr(md5(random()::text), 0, 10))
WHERE txhash='';
ALTER TABLE ursm_content_nodes ADD PRIMARY KEY (is_current, cnode_sp_id, txhash);
ALTER TABLE ursm_content_nodes ADD COLUMN IF NOT EXISTS slot INTEGER;
-- Drop NOT NULL Constraint on POA blockhash and tx hash columns
ALTER TABLE ursm_content_nodes ALTER COLUMN blockhash DROP NOT NULL;
ALTER TABLE ursm_content_nodes ALTER COLUMN blocknumber DROP NOT NULL;
ALTER TABLE follows DROP CONSTRAINT IF EXISTS follows_pkey;
UPDATE follows
SET txhash = ('unset_' || substr(md5(random()::text), 0, 10))
WHERE txhash='';
ALTER TABLE follows ADD PRIMARY KEY (is_current, follower_user_id, followee_user_id, txhash);
ALTER TABLE follows ADD COLUMN IF NOT EXISTS slot INTEGER;
-- Drop NOT NULL Constraint on POA blockhash and tx hash columns
ALTER TABLE follows ALTER COLUMN blockhash DROP NOT NULL;
ALTER TABLE follows ALTER COLUMN blocknumber DROP NOT NULL;
-- Drop NOT NULL Constraint on POA blockhash and tx hash columns
ALTER TABLE user_events ADD COLUMN IF NOT EXISTS slot INTEGER;
ALTER TABLE user_events ALTER COLUMN blockhash DROP NOT NULL;
ALTER TABLE user_events ALTER COLUMN blocknumber DROP NOT NULL;
commit;
"""
)


def downgrade():
connection = op.get_bind()
connection.execute(
"""
begin;
ALTER TABLE ursm_content_nodes DROP CONSTRAINT IF EXISTS ursm_content_nodes_pkey;
ALTER TABLE ursm_content_nodes ADD PRIMARY KEY (is_current, cnode_sp_id, blockhash, txhash);
ALTER TABLE ursm_content_nodes DROP COLUMN IF EXISTS slot;
-- Add NOT NULL Constraint on POA blockhash and tx hash columns
DELETE FROM ursm_content_nodes where blockhash IS NULL or blocknumber IS NULL;
ALTER TABLE ursm_content_nodes ALTER COLUMN blockhash SET NOT NULL;
ALTER TABLE ursm_content_nodes ALTER COLUMN blocknumber SET NOT NULL;
ALTER TABLE follows DROP CONSTRAINT IF EXISTS follows_pkey;
ALTER TABLE follows ADD PRIMARY KEY (is_current, follower_user_id, followee_user_id, blockhash, txhash);
ALTER TABLE follows DROP COLUMN IF EXISTS slot;
-- Add NOT NULL Constraint on POA blockhash and tx hash columns
ALTER TABLE follows ALTER COLUMN blockhash SET NOT NULL;
ALTER TABLE follows ALTER COLUMN blocknumber SET NOT NULL;
-- Drop NOT NULL Constraint on POA blockhash and tx hash columns
ALTER TABLE user_events DROP COLUMN IF EXISTS slot;
ALTER TABLE user_events ALTER COLUMN blockhash SET NOT NULL;
ALTER TABLE user_events ALTER COLUMN blocknumber SET NOT NULL;
commit;
"""
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""solana slot tracks
Revision ID: 2dbbc9c484e3
Revises: 11060779bb3a
Create Date: 2022-04-10 20:12:18.383547
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "2dbbc9c484e3"
down_revision = "11060779bb3a"
branch_labels = None
depends_on = None


def upgrade():
connection = op.get_bind()
connection.execute(
"""
begin;
ALTER TABLE tracks DROP CONSTRAINT IF EXISTS tracks_pkey;
UPDATE tracks
SET txhash = ('unset_' || substr(md5(random()::text), 0, 10))
WHERE txhash='';
ALTER TABLE tracks ADD PRIMARY KEY (is_current, track_id, txhash);
ALTER TABLE tracks ADD COLUMN IF NOT EXISTS slot INTEGER;
-- Drop NOT NULL Constraint on POA blockhash and tx hash columns
ALTER TABLE tracks ALTER COLUMN blockhash DROP NOT NULL;
ALTER TABLE tracks ALTER COLUMN blocknumber DROP NOT NULL;
commit;
"""
)


def downgrade():
connection = op.get_bind()
connection.execute(
"""
begin;
ALTER TABLE tracks DROP CONSTRAINT IF EXISTS tracks_pkey;
ALTER TABLE tracks ADD PRIMARY KEY (is_current, track_id, blockhash, txhash);
ALTER TABLE tracks DROP COLUMN IF EXISTS slot;
-- Add NOT NULL Constraint on POA blockhash and tx hash columns
DELETE FROM tracks where blockhash IS NULL or blocknumber IS NULL;
ALTER TABLE tracks ALTER COLUMN blockhash SET NOT NULL;
ALTER TABLE tracks ALTER COLUMN blocknumber SET NOT NULL;
commit;
"""
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""solana slot social
Revision ID: 3a3f2c9f5320
Revises: 2dbbc9c484e3
Create Date: 2022-04-10 20:13:10.421757
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "3a3f2c9f5320"
down_revision = "2dbbc9c484e3"
branch_labels = None
depends_on = None


def upgrade():
connection = op.get_bind()
connection.execute(
"""
begin;
ALTER TABLE playlists DROP CONSTRAINT IF EXISTS playlists_pkey;
UPDATE playlists
SET txhash = ('unset_' || substr(md5(random()::text), 0, 10))
WHERE txhash='';
ALTER TABLE playlists ADD PRIMARY KEY (is_current, playlist_id, txhash);
ALTER TABLE playlists ADD COLUMN IF NOT EXISTS slot INTEGER;
-- Drop NOT NULL Constraint on POA blockhash and tx hash columns
ALTER TABLE playlists ALTER COLUMN blockhash DROP NOT NULL;
ALTER TABLE playlists ALTER COLUMN blocknumber DROP NOT NULL;
commit;
"""
)


def downgrade():
connection = op.get_bind()
connection.execute(
"""
begin;
ALTER TABLE playlists DROP CONSTRAINT IF EXISTS playlists_pkey;
ALTER TABLE playlists ADD PRIMARY KEY (is_current, playlist_id, playlist_owner_id, blockhash, txhash);
ALTER TABLE playlists DROP COLUMN IF EXISTS slot;
-- Add NOT NULL Constraint on POA blockhash and tx hash columns
DELETE FROM playlists where blockhash IS NULL or blocknumber IS NULL;
ALTER TABLE playlists ALTER COLUMN blockhash SET NOT NULL;
ALTER TABLE playlists ALTER COLUMN blocknumber SET NOT NULL;
commit;
"""
)

0 comments on commit 95f3aa8

Please sign in to comment.