Skip to content

Commit

Permalink
db: drop unused columns from users table.
Browse files Browse the repository at this point in the history
Note that the password_hash column was replaced by bcrypt_password_hash
in 2013, but the old password_hash column was never dropped.
  • Loading branch information
evazion committed Nov 17, 2019
1 parent 90713ef commit 364ecfe
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
1 change: 0 additions & 1 deletion app/logical/user_deletion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def clear_user_settings
user.email = nil
user.last_logged_in_at = nil
user.last_forum_read_at = nil
user.recent_tags = ''
user.favorite_tags = ''
user.blacklisted_tags = ''
user.hide_deleted_posts = false
Expand Down
3 changes: 1 addition & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ def bcrypt_cookie_password_hash
end

def encrypt_password_on_create
self.password_hash = ""
self.bcrypt_password_hash = User.bcrypt(password)
end

Expand Down Expand Up @@ -581,7 +580,7 @@ def api_attributes
attributes += BOOLEAN_ATTRIBUTES
attributes += [
:updated_at, :email, :last_logged_in_at, :last_forum_read_at,
:recent_tags, :comment_threshold, :default_image_size,
:comment_threshold, :default_image_size,
:favorite_tags, :blacklisted_tags, :time_zone, :per_page,
:custom_style, :favorite_count, :api_regen_multiplier,
:api_burst_limit, :remaining_api_limit, :statement_timeout,
Expand Down
1 change: 0 additions & 1 deletion config/danbooru_default_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def customize_new_user(user)
# user.can_upload_free = false
# user.is_super_voter = false
#
# user.base_upload_limit = 10
# user.comment_threshold = -1
# user.blacklisted_tags = ["spoilers", "guro", "scat", "furry -rating:s"].join("\n")
# user.default_image_size = "large"
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20191116224228_drop_unused_columns_from_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class DropUnusedColumnsFromUsers < ActiveRecord::Migration[6.0]
def change
execute "set statement_timeout = 0"

remove_column :users, :base_upload_limit, :integer, null: false, default: 10
remove_column :users, :recent_tags, :string
remove_column :users, :email_verification_key, :string
remove_column :users, :password_hash, :string, null: false
end
end
7 changes: 2 additions & 5 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2235,18 +2235,14 @@ ALTER TABLE ONLY public.posts ALTER COLUMN tag_index SET STATISTICS 2000;
CREATE TABLE public.users (
id integer NOT NULL,
name character varying NOT NULL,
password_hash character varying NOT NULL,
level integer DEFAULT 20 NOT NULL,
email character varying,
recent_tags text DEFAULT ''::text NOT NULL,
inviter_id integer,
created_at timestamp without time zone NOT NULL,
last_logged_in_at timestamp without time zone DEFAULT now(),
last_forum_read_at timestamp without time zone DEFAULT '1960-01-01 00:00:00'::timestamp without time zone,
base_upload_limit integer,
comment_threshold integer DEFAULT 0 NOT NULL,
updated_at timestamp without time zone,
email_verification_key character varying,
default_image_size character varying DEFAULT 'large'::character varying NOT NULL,
favorite_tags text,
blacklisted_tags text DEFAULT 'spoilers
Expand Down Expand Up @@ -7552,6 +7548,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20191111004329'),
('20191111024520'),
('20191116001441'),
('20191116021759');
('20191116021759'),
('20191116224228');


2 changes: 0 additions & 2 deletions test/factories/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
"user#{n}"
end
password {"password"}
password_hash {User.sha1("password")}
email {FFaker::Internet.email}
default_image_size {"large"}
base_upload_limit {10}
level {20}
created_at {Time.now}
last_logged_in_at {Time.now}
Expand Down

0 comments on commit 364ecfe

Please sign in to comment.