<commit_before>Skiima: an ORM-Agnostic, Rails-Independent alternative to migrations.

[![Build Status](https://travis-ci.org/dcunited001/skiima.png?branch=master)](https://travis-ci.org/dcunited001/skiima)

------------------------

## Using Skiima with ActiveRecord:

> Adding generators soon

#### Installing
1. Add skiima to your Gemfile
1. Bundle Install
1. Configure your database.yml
  - Ensure that users have the appropriate DDL permissions
1. `mkdir db/skiima`
1. `touch db/skiima/dependencies.yml`
  - Refer to the example below or $SKIIMA_GEM/spec/db/skiima/dependencies
1. Set up a :test dependency group
  - include the groups of scripts you want to run after a fresh db clone
  - add `bundle exec rake skiima:test:up` to your CI setup script, after calling db:test:prepare
  - or add a rake task to your project that calls both db:test:prepare and skima:test:up
  - specify environment/groups with `bundle exec rake skiima:test:up[development,group_name]
1. Set up a :default dependency group
  - include the groups of scripts you want to run during every deploy
  - because the scripts are run on each deploy, this rake task should only be used in certain instances
  - you should usually call Skiima.up & Skiima.down from a migration

#### Adding a new Skiima Script Group to your project

> Again, generators coming soon to help automate this.

1. Add a new migration to your Rails project.  Refer to the sample below.
1. `mkdir db/skiima/$group_name`
1. `touch db/skiima/$group_name/$type.$object_name.$db_type.$db_version.sql`
  - $type => view/proc/function/etc
  - $object_name => identifies the script across multiple db providers & versions
  - $db_type => provider name (mysql/postgres)
  - $db_version => usually just 'current'
    - using $db_version, you can write scripts to support multiple versions of mysql, for example
    - Skiima compares the connected database's version to pull the correct script
    - or you can just configure skiima to prefer to load specific version of sql scripts
    - pass :version => 'version_name' to Skiima.up & Skiima.down
1. Also add a corresponding drop script to run if:
  - either the up script is not reversible with a single drop statement
  - or if Skiima can not automatically drop that type object
  - see below for supported objects
1. Now update db/skiima/dependencies.yml
  - Refer to the example below or $SKIIMA_GEM/spec/db/skiima/dependencies
1. The script should be ready to use with Skiima.up & Skiima.down

Sample Skiima Migration:

```ruby

class AddViewBackedModel < ActiveRecord::Migration
  def up
    Skiima.up(Rails.env, :group_name)
  end

  def down
    Skiima.down(Rails.env, :group_name)
  end
end

```

Sample Dependencies.yml:

```yml

script_group_name:
  postgresql:
    current:
      - view.script_name
  mysql:
    current:
      - view.script_name
dependency_group_name:
  - script_group_name

# load/drop these script groups with:
#   `rake skiima:up` & `rake skiima:down`
# List migrations you have already squashed
# - IE migrations that you removed to rely on schema.rb
default:
- script_group_a
- script_group_b
- script_group_c

# load/drop these script groups with:
#   `rake skiima:test:up` & `rake skiima:test:down`
# For tests/CI!
# List migrations that need to be run after a blank db is migrated
# - IE migrations that you squashed, if you are migrating from scratch on CI
# - If relying on db/schema.rb for CI, then list the groups you need for tests
test:
- script_group_a
- script_group_b
- script_group_c

```

#### Running tests with your new Skiima Script Group

1. `bundle exec rake db:migrate`
1. `bundle exec rake db:test:prepare`
1. `bundle exec rake skiima:test:up`
1. `bundle exec rake`

#### Adding a view-backed model

```ruby
# add a view named 'view_foo_report_on_bar'
class FooReportOnBar < ActiveRecord::Base
  set_table_name :view_foo_report_on_bar

  belongs_to :baz
end
```

## Using Skiima with another ORM:

> Support for Datamapper, Sequal, & JRuby providers coming soon.

## Running Tests

1. Setup Mysql & Postgres.  Copy database.yml.example & set up users/passwords for your system
1. Bundle Install
1. Run test setup tasks
  - bundle exec rake skiima:setup:db:postgresql
  - bundle exec rake skiima:setup:db:mysql
1. `rake`

## Skiima Goals:
* Provide a better way to integrate views and functions into Ruby applications.<commit_msg>added details for running tests<commit_after>Skiima: an ORM-Agnostic, Rails-Independent alternative to migrations.

[![Build Status](https://travis-ci.org/dcunited001/skiima.png?branch=master)](https://travis-ci.org/dcunited001/skiima)

------------------------

## Using Skiima with ActiveRecord:

> Adding generators soon

#### Installing
1. Add skiima to your Gemfile
1. Bundle Install
1. Configure your database.yml
  - Ensure that users have the appropriate DDL permissions
1. `mkdir db/skiima`
1. `touch db/skiima/dependencies.yml`
  - Refer to the example below or $SKIIMA_GEM/spec/db/skiima/dependencies
1. Set up a :test dependency group
  - include the groups of scripts you want to run after a fresh db clone
  - add `bundle exec rake skiima:test:up` to your CI setup script, after calling db:test:prepare
  - or add a rake task to your project that calls both db:test:prepare and skima:test:up
  - specify environment/groups with `bundle exec rake skiima:test:up[development,group_name]
1. Set up a :default dependency group
  - include the groups of scripts you want to run during every deploy
  - because the scripts are run on each deploy, this rake task should only be used in certain instances
  - you should usually call Skiima.up & Skiima.down from a migration

#### Adding a new Skiima Script Group to your project

> Again, generators coming soon to help automate this.

1. Add a new migration to your Rails project.  Refer to the sample below.
1. `mkdir db/skiima/$group_name`
1. `touch db/skiima/$group_name/$type.$object_name.$db_type.$db_version.sql`
  - $type => view/proc/function/etc
  - $object_name => identifies the script across multiple db providers & versions
  - $db_type => provider name (mysql/postgres)
  - $db_version => usually just 'current'
    - using $db_version, you can write scripts to support multiple versions of mysql, for example
    - Skiima compares the connected database's version to pull the correct script
    - or you can just configure skiima to prefer to load specific version of sql scripts
    - pass :version => 'version_name' to Skiima.up & Skiima.down
1. Also add a corresponding drop script to run if:
  - either the up script is not reversible with a single drop statement
  - or if Skiima can not automatically drop that type object
  - see below for supported objects
1. Now update db/skiima/dependencies.yml
  - Refer to the example below or $SKIIMA_GEM/spec/db/skiima/dependencies
1. The script should be ready to use with Skiima.up & Skiima.down

Sample Skiima Migration:

```ruby

class AddViewBackedModel < ActiveRecord::Migration
  def up
    Skiima.up(Rails.env, :group_name)
  end

  def down
    Skiima.down(Rails.env, :group_name)
  end
end

```

Sample Dependencies.yml:

```yml

script_group_name:
  postgresql:
    current:
      - view.script_name
  mysql:
    current:
      - view.script_name
dependency_group_name:
  - script_group_name

# load/drop these script groups with:
#   `rake skiima:up` & `rake skiima:down`
# List migrations you have already squashed
# - IE migrations that you removed to rely on schema.rb
default:
- script_group_a
- script_group_b
- script_group_c

# load/drop these script groups with:
#   `rake skiima:test:up` & `rake skiima:test:down`
# For tests/CI!
# List migrations that need to be run after a blank db is migrated
# - IE migrations that you squashed, if you are migrating from scratch on CI
# - If relying on db/schema.rb for CI, then list the groups you need for tests
test:
- script_group_a
- script_group_b
- script_group_c

```

#### Running tests with your new Skiima Script Group

1. `bundle exec rake db:migrate`
1. `bundle exec rake db:test:prepare`
1. `bundle exec rake skiima:test:up`
1. `bundle exec rake`

#### Adding a view-backed model

```ruby
# add a view named 'view_foo_report_on_bar'
class FooReportOnBar < ActiveRecord::Base
  set_table_name :view_foo_report_on_bar

  belongs_to :baz
end
```

## Using Skiima with another ORM:

> Support for Datamapper, Sequal, & JRuby providers coming soon.

## Running Tests

1. Setup Mysql & Postgres. I recommend copying Procfile.example and using foreman.
1. Copy database.yml.example & set up users/passwords for your system
  - configure an existing user/password for postgresql_root & mysql_root
  - this user creates a user for the test databases in the rake setup tasks
1. Bundle Install
1. Run test setup tasks
  - `bundle exec rake skiima:setup:db:postgresql`
  - `bundle exec rake skiima:setup:db:mysql`
    - you may need to remove the `DROP USER` command in `spec/db/skiima/init_test_db/database.skiima_test.mysql.current.sql`
1. `rake`

## Skiima Goals:
* Provide a better way to integrate views and functions into Ruby applications.
{'fraction_non_alphanumeric': 0.08503625576796309, 'fraction_numerical': 0.006042627993847506, 'mean_word_length': 3.8809651474530833, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2288225', 'n_tokens_mistral': 2878, 'n_tokens_neox': 2756, 'n_words': 1103}