changeset 460:b1ef80121c79

Update to use correct timestamp datatype Use sql dump instead of ruby because zone info would be lost otherwise.
author nanaya <me@nanaya.pro>
date Mon, 25 Jun 2018 16:53:47 +0900
parents 07d6c6639adf
children 51d4c4e60018
files config/application.rb db/migrate/20180625074738_convert_timestamps_to_with_time_zone.rb db/schema.rb db/structure.sql
diffstat 4 files changed, 191 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/config/application.rb	Sat Apr 14 04:19:52 2018 +0900
+++ b/config/application.rb	Mon Jun 25 16:53:47 2018 +0900
@@ -54,7 +54,7 @@
     # Use SQL instead of Active Record's schema dumper when creating the database.
     # This is necessary if your schema can't be completely dumped by the schema dumper,
     # like if you have constraints or database-specific column types
-    # config.active_record.schema_format = :sql
+    config.active_record.schema_format = :sql
 
     # Enable the asset pipeline
     config.assets.enabled = true
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/db/migrate/20180625074738_convert_timestamps_to_with_time_zone.rb	Mon Jun 25 16:53:47 2018 +0900
@@ -0,0 +1,26 @@
+class ConvertTimestampsToWithTimeZone < ActiveRecord::Migration[5.2]
+  COLUMNS = {
+    ar_internal_metadata: [:created_at, :updated_at],
+    pastes: [:created_at, :updated_at],
+  }
+
+  def up
+    COLUMNS.each do |table, columns|
+      change_table table do |t|
+        columns.each do |column|
+          t.change column, :timestamptz
+        end
+      end
+    end
+  end
+
+  def down
+    COLUMNS.each do |table, columns|
+      change_table table do |t|
+        columns.each do |column|
+          t.change column, :timestamp
+        end
+      end
+    end
+  end
+end
--- a/db/schema.rb	Sat Apr 14 04:19:52 2018 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-# encoding: UTF-8
-# This file is auto-generated from the current state of the database. Instead
-# of editing this file, please use the migrations feature of Active Record to
-# incrementally modify your database, and then regenerate this schema definition.
-#
-# Note that this schema.rb definition is the authoritative source for your
-# database schema. If you need to create the application database on another
-# system, you should be using db:schema:load, not running all the migrations
-# from scratch. The latter is a flawed and unsustainable approach (the more migrations
-# you'll amass, the slower it'll run and the greater likelihood for issues).
-#
-# It's strongly recommended that you check this file into your version control system.
-
-ActiveRecord::Schema.define(version: 20150916161622) do
-
-  create_table "pastes", force: :cascade do |t|
-    t.string   "ip",         limit: 50,  null: false
-    t.text     "paste",                  null: false
-    t.string   "paste_hash", limit: 150, null: false
-    t.datetime "created_at",             null: false
-    t.datetime "updated_at",             null: false
-    t.string   "key",        limit: 100
-    t.string   "secret",     limit: 100
-    t.string   "language",   limit: 100
-  end
-
-  add_index "pastes", ["ip", "paste_hash"], name: "index_pastes_on_ip_and_hash", unique: true, using: :btree
-  add_index "pastes", ["secret"], name: "index_pastes_on_secret", using: :btree
-
-end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/db/structure.sql	Mon Jun 25 16:53:47 2018 +0900
@@ -0,0 +1,164 @@
+SET statement_timeout = 0;
+SET lock_timeout = 0;
+SET idle_in_transaction_session_timeout = 0;
+SET client_encoding = 'UTF8';
+SET standard_conforming_strings = on;
+SELECT pg_catalog.set_config('search_path', '', false);
+SET check_function_bodies = false;
+SET client_min_messages = warning;
+SET row_security = off;
+
+--
+-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -
+--
+
+CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
+
+
+--
+-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: -
+--
+
+COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
+
+
+--
+-- Name: hstore; Type: EXTENSION; Schema: -; Owner: -
+--
+
+CREATE EXTENSION IF NOT EXISTS hstore WITH SCHEMA public;
+
+
+--
+-- Name: EXTENSION hstore; Type: COMMENT; Schema: -; Owner: -
+--
+
+COMMENT ON EXTENSION hstore IS 'data type for storing sets of (key, value) pairs';
+
+
+SET default_tablespace = '';
+
+SET default_with_oids = false;
+
+--
+-- Name: ar_internal_metadata; Type: TABLE; Schema: public; Owner: -
+--
+
+CREATE TABLE public.ar_internal_metadata (
+    key character varying NOT NULL,
+    value character varying,
+    created_at timestamp with time zone NOT NULL,
+    updated_at timestamp with time zone NOT NULL
+);
+
+
+--
+-- Name: pastes; Type: TABLE; Schema: public; Owner: -
+--
+
+CREATE TABLE public.pastes (
+    id integer NOT NULL,
+    ip character varying(50) NOT NULL,
+    paste text NOT NULL,
+    paste_hash character varying(150) NOT NULL,
+    created_at timestamp with time zone NOT NULL,
+    updated_at timestamp with time zone NOT NULL,
+    key character varying(100),
+    secret character varying(100),
+    language character varying(100)
+);
+
+
+--
+-- Name: pastes_id_seq; Type: SEQUENCE; Schema: public; Owner: -
+--
+
+CREATE SEQUENCE public.pastes_id_seq
+    AS integer
+    START WITH 1
+    INCREMENT BY 1
+    NO MINVALUE
+    NO MAXVALUE
+    CACHE 1;
+
+
+--
+-- Name: pastes_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
+--
+
+ALTER SEQUENCE public.pastes_id_seq OWNED BY public.pastes.id;
+
+
+--
+-- Name: schema_migrations; Type: TABLE; Schema: public; Owner: -
+--
+
+CREATE TABLE public.schema_migrations (
+    version character varying NOT NULL
+);
+
+
+--
+-- Name: pastes id; Type: DEFAULT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.pastes ALTER COLUMN id SET DEFAULT nextval('public.pastes_id_seq'::regclass);
+
+
+--
+-- Name: ar_internal_metadata ar_internal_metadata_pkey; Type: CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.ar_internal_metadata
+    ADD CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key);
+
+
+--
+-- Name: pastes pastes_pkey; Type: CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.pastes
+    ADD CONSTRAINT pastes_pkey PRIMARY KEY (id);
+
+
+--
+-- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.schema_migrations
+    ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version);
+
+
+--
+-- Name: index_pastes_on_ip_and_hash; Type: INDEX; Schema: public; Owner: -
+--
+
+CREATE UNIQUE INDEX index_pastes_on_ip_and_hash ON public.pastes USING btree (ip, paste_hash);
+
+
+--
+-- Name: index_pastes_on_secret; Type: INDEX; Schema: public; Owner: -
+--
+
+CREATE INDEX index_pastes_on_secret ON public.pastes USING btree (secret);
+
+
+--
+-- PostgreSQL database dump complete
+--
+
+SET search_path TO "$user", public;
+
+INSERT INTO "schema_migrations" (version) VALUES
+('20120826180414'),
+('20120826182012'),
+('20120905072325'),
+('20120905074204'),
+('20130201150322'),
+('20130511133450'),
+('20130512032335'),
+('20150914054154'),
+('20150916161622'),
+('20180625074738');
+
+