database

ruby
class AddIndexesToPosts < ActiveRecord::Migration[6.1]
  def change
    add_index :posts, :author_id
    add_index :posts, :published_at
    add_index :posts, [:author_id, :published_at]
    add_index :posts, :created_at, order: { created_at: :desc }

Database indexes for query optimization

rails postgresql database
by Alex Kumar 1 tab
python
from django.db import transaction
from django.http import JsonResponse


@transaction.atomic
def transfer_funds(request):

Django atomic transactions for data integrity

django python database
by Priya Sharma 1 tab
sql
-- Import CSV with COPY (fastest method)
COPY users (username, email, age, created_at)
FROM '/path/to/users.csv'
WITH (
  FORMAT csv,
  HEADER true,

Efficient data import and export strategies

database import export
by Maria Garcia 2 tabs
ruby
class TransferFundsService
  def initialize(from_account:, to_account:, amount:)
    @from_account = from_account
    @to_account = to_account
    @amount = amount
  end

Database transactions for data consistency

rails database activerecord
by Alex Kumar 1 tab
python
# Find products with specific spec value
products = Product.objects.filter(specs__weight__gte=100)

# Check if JSON key exists
products = Product.objects.filter(specs__has_key='color')

Django JSON field for flexible schema data

django python jsonfield
by Priya Sharma 2 tabs
ruby
class AddConstraintsToUsers < ActiveRecord::Migration[6.1]
  def change
    # Null constraints
    change_column_null :users, :email, false
    change_column_null :users, :username, false

Database constraints for data integrity

rails postgresql database
by Alex Kumar 1 tab
python
from products.models import Product


def import_products_bulk(product_data):
    """Import thousands of products efficiently."""
    products = [

Django bulk operations for performance

django python performance
by Priya Sharma 1 tab
java
package com.example.demo.service;

import com.example.demo.model.Order;
import com.example.demo.model.OrderItem;
import com.example.demo.model.User;
import com.example.demo.repository.OrderRepository;

Database transactions and isolation levels

java spring-boot transactions
by David Kumar 2 tabs
ruby
class AddStatusToPosts < ActiveRecord::Migration[6.1]
  # Use change for automatic rollback
  def change
    # Add column without default to avoid table lock
    add_column :posts, :status, :string

Rails database migrations best practices

rails migrations database
by Maya Patel 3 tabs
yaml
production:
  primary:
    adapter: postgresql
    url: <%= ENV['DATABASE_URL'] %>
    pool: <%= ENV.fetch("RAILS_MAX_THREADS", 5) %>
  primary_replica:

Database read replicas for scaling reads

rails postgresql scaling
by Alex Kumar 3 tabs
ruby
module StatementTimeout
  extend ActiveSupport::Concern

  class TimeoutExceeded < StandardError; end

  def with_statement_timeout(milliseconds)

Guard Against Slow Queries with statement_timeout

rails postgres performance
by codesnips 3 tabs
python
from django.db import migrations


def populate_slugs(apps, schema_editor):
    """Generate slugs for existing posts."""
    Post = apps.get_model('blog', 'Post')

Django database migrations best practices

django python migrations
by Priya Sharma 1 tab