Sha256: 7497952ac160ddd32012dd5c16e21ffcfd6675e538c6cc7412d055b2ab418ebe

Contents?: true

Size: 995 Bytes

Versions: 2

Compression:

Stored size: 995 Bytes

Contents

# Defines the table schemas. Acts as migration.
#
# Npte the executing below the classes. These create the tables
module Timetrap
  class Schema
    def self.create_table!
      DB.drop_table(self::TABLE)
      create_table
    end

    def self.create_table
      self.new.create_table
    end

    def self.try_create_table
      create_table unless DB.table_exists?(self::TABLE)
    end
  end

  class EntrySchema < Schema
    TABLE = :entries
    def create_table
      DB.create_table(TABLE) do
        primary_key :id
        column :note, String
        column :start, DateTime
        column :end, DateTime
        column :sheet, String
      end
    end
  end

  class MetaSchema < Schema
    TABLE = :meta
    def create_table
      DB.create_table(TABLE) do
        primary_key :id
        column :key, String
        column :value, String
      end
    end
  end

  ## Executes the schema, acting as a small migration
  EntrySchema.try_create_table
  MetaSchema.try_create_table
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
timetrap-1.15.4 lib/timetrap/schema.rb
timetrap-1.15.2 lib/timetrap/schema.rb