Class: DbMemoize::Migrations

Inherits:
Object
  • Object
show all
Defined in:
lib/db_memoize/migrations.rb

Class Method Summary collapse

Class Method Details

.create_tables(migration) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/db_memoize/migrations.rb', line 4

def create_tables(migration)
  migration.execute <<~SQL
    CREATE SCHEMA IF NOT EXISTS db_memoize;

    CREATE TABLE IF NOT EXISTS db_memoize.memoized_values (
      entity_table_name varchar NOT NULL,
      entity_id         integer NOT NULL,
      method_name       varchar NOT NULL,

      val_string        varchar,
      val_integer       bigint,
      val_float         double precision,
      val_time          timestamp without time zone,
      val_object        jsonb,
      val_boolean       boolean,
      val_nil           boolean,
      created_at        timestamp without time zone NOT NULL
    );

    -- entity_id/entity_table_name should have a better chance to be useful, since
    -- there is more variance in entity_ids than there is in entity_table_names.
    DROP INDEX IF EXISTS db_memoize.memoized_attributes_idx2;

    CREATE INDEX IF NOT EXISTS memoized_attributes_idx3
      ON db_memoize.memoized_values(entity_id, entity_table_name);
  SQL
end