1

For debugging purposes I would like to know when are some of my postgres schemas created at- is it possible?

Searched from PostgreSQL and Apartment docs but didn't find any helpful clues.

Environment and tools I'm using:

+---------------+----------+
| Tools         | Version  |
+--------------------------+
| PostgreSQL    | 9.4.1    |
| Ruby          | 2.2.1p85 |
| Ruby on Rails | 4.1.9    |
| Apartment gem | 0.26.1   |
+---------------+----------+

As you can see I use Apartment for creating schemas in my multi-tenant rails application.

4

4 回答 4

1

您可以创建一个事件触发器并将此事件的日期存储在一个表中。示例可以在这里找到

于 2015-04-15T10:27:09.673 回答
1

PostgreSQL 系统目录不存储创建数据库对象的日期。您可以将 PostgreSQL 配置为或多或少地记录每个 SQL 语句(log_statement 设置),但您必须事先这样做。

于 2015-04-15T09:54:40.787 回答
0

I'll post a "Rails way" solution that will not work for previously made schemas but new-ones.

  1. Create model for tenants rails g model Tenant name:string
  2. Add after_create callback for Tenant model

    class Tenant < ActiveRecord::Base
      after_create :tenant_moves_in
    
      private
    
      def tenant_moves_in
        Apartment::Tenant.create self.name
      end
    
  3. For ex. create somekind of script for making tenants or use ActiveRecord CRUD ability with Tenant model to operate with tenants in your app directly like Tenant.create(name: 'new_tenant').

Thatway you can have created_at and updated_at dates in your db tenants table in relation to Apartment Tenants, which represent postgres schemas.

Of course then you should avoid making tenants with Aparmtent tool like Apartment::Tenant.create 'new_tenant' because that will not create a Tenant-model object and therefore no created_at time will be preserved.

于 2015-04-16T19:24:37.183 回答
-1

免责声明:这回答了对问题的错误解释。我保留它以防它对某人有用...

当您使用 运行 Ruby on Rails 迁移时rake db:migrate,rails 会维护一个文件,向您显示数据库结构的快照。该文件位于db/schema.rb.

下面是一个created_at由 rails 添加的表格示例:

  create_table "comments", force: true do |t|
    t.integer  "user_id"
    t.integer  "article_id"
    t.text     "content"
    t.datetime "created_at",                 null: false
    t.datetime "updated_at",                 null: false
    t.string   "origin",     default: "web"
  end

更多细节在这里: http ://edgeguides.rubyonrails.org/active_record_migrations.html

于 2015-04-15T09:32:34.993 回答